Module netmiko.raisecom
+Source code
+from netmiko.raisecom.raisecom_roap import RaisecomRoapSSH
+from netmiko.raisecom.raisecom_roap import RaisecomRoapTelnet
+
+__all__ = ["RaisecomRoapSSH", "RaisecomRoapTelnet"]
+Sub-modules
+-
+
netmiko.raisecom.raisecom_roap
+- + + +
Classes
+-
+
+class RaisecomRoapSSH +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +
+-
+
+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 RaisecomRoapSSH(RaisecomRoapBase): + def special_login_handler(self, delay_factor=1): + """ + Raisecom presents with the following on login (in certain OS versions) + Login: user + Password:**** + """ + delay_factor = self.select_delay_factor(delay_factor) + i = 0 + time.sleep(delay_factor * 0.5) + output = "" + while i <= 12: + output = self.read_channel() + if output: + if "Login:" in output: + self.write_channel(self.username + self.RETURN) + elif "Password:" in output: + self.write_channel(self.password + self.RETURN) + break + time.sleep(delay_factor * 1) + else: + self.write_channel(self.RETURN) + time.sleep(delay_factor * 1.5) + i += 1
Ancestors
+ +Methods
+-
+
+def special_login_handler(self, delay_factor=1) +
+-
+
+Raisecom presents with the following on login (in certain OS versions) +Login: user +Password:****
++Source code
+
+def special_login_handler(self, delay_factor=1): + """ + Raisecom presents with the following on login (in certain OS versions) + Login: user + Password:**** + """ + delay_factor = self.select_delay_factor(delay_factor) + i = 0 + time.sleep(delay_factor * 0.5) + output = "" + while i <= 12: + output = self.read_channel() + if output: + if "Login:" in output: + self.write_channel(self.username + self.RETURN) + elif "Password:" in output: + self.write_channel(self.password + self.RETURN) + break + time.sleep(delay_factor * 1) + else: + self.write_channel(self.RETURN) + time.sleep(delay_factor * 1.5) + i += 1
+
Inherited members
+-
+
RaisecomRoapBase
: +-
+
check_config_mode
+check_enable_mode
+cleanup
+clear_buffer
+close_session_log
+commit
+config_mode
+disable_paging
+disconnect
+enable
+establish_connection
+exit_config_mode
+exit_enable_mode
+find_prompt
+is_alive
+normalize_cmd
+normalize_linefeeds
+open_session_log
+paramiko_cleanup
+read_channel
+read_until_pattern
+read_until_prompt
+read_until_prompt_or_pattern
+save_config
+select_delay_factor
+send_command
+send_command_expect
+send_command_timing
+send_config_from_file
+send_config_set
+session_preparation
+set_base_prompt
+set_terminal_width
+strip_ansi_escape_codes
+strip_backspaces
+strip_command
+strip_prompt
+telnet_login
+write_channel
+
+
+ +class RaisecomRoapTelnet +(ip='', host='', username='', password=None, secret='', port=None, device_type='', verbose=False, global_delay_factor=1, global_cmd_verify=None, use_keys=False, key_file=None, pkey=None, passphrase=None, allow_agent=False, ssh_strict=False, system_host_keys=False, alt_host_keys=False, alt_key_file='', ssh_config_file=None, conn_timeout=5, auth_timeout=None, banner_timeout=15, blocking_timeout=20, timeout=100, session_timeout=60, keepalive=0, default_enter=None, response_return=None, serial_settings=None, fast_cli=False, session_log=None, session_log_record_writes=False, session_log_file_mode='write', allow_auto_change=False, encoding='ascii', sock=None, auto_connect=True) +
+-
+
+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 RaisecomRoapTelnet(RaisecomRoapBase): + @staticmethod + def _process_option(telnet_sock, cmd, opt): + """ + enable ECHO, SGA, set window size to [500, 50] + """ + if cmd == WILL: + if opt in [ECHO, SGA]: + # reply DO ECHO / DO SGA + telnet_sock.sendall(IAC + DO + opt) + else: + telnet_sock.sendall(IAC + DONT + opt) + elif cmd == DO: + if opt == NAWS: + # negotiate about window size + telnet_sock.sendall(IAC + WILL + opt) + # Width:500, Weight:50 + telnet_sock.sendall(IAC + SB + NAWS + b"\x01\xf4\x00\x32" + IAC + SE) + else: + telnet_sock.sendall(IAC + WONT + opt) + + def telnet_login( + self, + pri_prompt_terminator=r"#\s*$", + alt_prompt_terminator=r">\s*$", + username_pattern=r"(Login|Username)", + pwd_pattern=r"Password", + delay_factor=1, + max_loops=20, + ): + + # set callback function to handle telnet options. + self.remote_conn.set_option_negotiation_callback(self._process_option) + delay_factor = self.select_delay_factor(delay_factor) + time.sleep(1 * delay_factor) + + output = "" + return_msg = "" + i = 1 + while i <= max_loops: + try: + output = self.read_channel() + return_msg += output + + # Search for username pattern / send username + if re.search(username_pattern, output, flags=re.I): + self.write_channel(self.username + self.TELNET_RETURN) + time.sleep(1 * delay_factor) + output = self.read_channel() + return_msg += output + + # Search for password pattern / send password + if re.search(pwd_pattern, output, flags=re.I): + self.write_channel(self.password + self.TELNET_RETURN) + time.sleep(0.5 * delay_factor) + output = self.read_channel() + return_msg += output + if re.search( + pri_prompt_terminator, output, flags=re.M + ) or re.search(alt_prompt_terminator, output, flags=re.M): + return return_msg + + # Check if proper data received + if re.search(pri_prompt_terminator, output, flags=re.M) or re.search( + alt_prompt_terminator, output, flags=re.M + ): + return return_msg + + time.sleep(0.5 * delay_factor) + i += 1 + except EOFError: + self.remote_conn.close() + msg = f"Login failed: {self.host}" + raise NetmikoAuthenticationException(msg) + + # Last try to see if we already logged in + self.write_channel(self.TELNET_RETURN) + time.sleep(0.5 * delay_factor) + output = self.read_channel() + return_msg += output + if re.search(pri_prompt_terminator, output, flags=re.M) or re.search( + alt_prompt_terminator, output, flags=re.M + ): + return return_msg + + msg = f"Login failed: {self.host}" + self.remote_conn.close() + raise NetmikoAuthenticationException(msg)
Ancestors
+ +Inherited members
+-
+
RaisecomRoapBase
: +-
+
check_config_mode
+check_enable_mode
+cleanup
+clear_buffer
+close_session_log
+commit
+config_mode
+disable_paging
+disconnect
+enable
+establish_connection
+exit_config_mode
+exit_enable_mode
+find_prompt
+is_alive
+normalize_cmd
+normalize_linefeeds
+open_session_log
+paramiko_cleanup
+read_channel
+read_until_pattern
+read_until_prompt
+read_until_prompt_or_pattern
+save_config
+select_delay_factor
+send_command
+send_command_expect
+send_command_timing
+send_config_from_file
+send_config_set
+session_preparation
+set_base_prompt
+set_terminal_width
+special_login_handler
+strip_ansi_escape_codes
+strip_backspaces
+strip_command
+strip_prompt
+telnet_login
+write_channel
+
+
+