def _disable_paging_external_function(self, setup_use_paramiko): with ssh2net.SSH2Net( **self.test_device, setup_use_paramiko=setup_use_paramiko, comms_disable_paging=self.disable_paging_ext_function, ) as conn: show_run = conn.send_inputs("show run")[0] show_run = self.clean_input_data(show_run) return show_run
def _send_inputs_interact(self, setup_use_paramiko, interact, **kwargs): with ssh2net.SSH2Net(**self.test_device, setup_use_paramiko=setup_use_paramiko) as conn: try: current_prompt = interact[3] except IndexError: current_prompt = conn.get_prompt() interactive = conn.send_inputs_interact( (interact[0], interact[1], interact[2], current_prompt), **kwargs)[0] return interactive
# Setup session logging; session logging is connection stuff only -- i.e. socket/session/channel session_log_file = "session.log" # Set the "ssh2net_session" logger session_logger = logging.getLogger("ssh2net_session") # Set log level to level of your choice session_logger.setLevel(logging.DEBUG) session_logger_file_handler = logging.FileHandler(session_log_file) # Assign formatter to log handler session_logger_file_handler.setFormatter(logging.Formatter(log_format)) # Add log handler to the session_logger session_logger.addHandler(session_logger_file_handler) # Do not propagate logs to stdout session_logger.propagate = False # Repeat similar steps as above for channel logger; channel logger captures reads/writes # ssh2net_channel logger removes duplicate entries from the log to avoid logs being massive channel_log_file = "channel.log" channel_logger = logging.getLogger("ssh2net_channel") channel_logger.setLevel(logging.DEBUG) channel_logger_file_handler = logging.FileHandler(channel_log_file) channel_logger_file_handler.setFormatter(logging.Formatter(log_format)) channel_logger.addHandler(channel_logger_file_handler) channel_logger.propagate = False my_device = {"setup_host": "172.18.0.11", "auth_user": "******", "auth_password": "******"} with ssh2net.SSH2Net(**my_device) as conn: show_run = conn.send_inputs("show run") print(show_run[0])
def show_run_inputs_no_strip_prompt(self, setup_use_paramiko, command): with ssh2net.SSH2Net(**self.test_device, setup_use_paramiko=setup_use_paramiko) as conn: show_run = conn.send_inputs(command, strip_prompt=False)[0] show_run = self.clean_input_data(show_run) return show_run
def show_run_execute(self): conn = ssh2net.SSH2Net(**self.test_device) show_run = conn.open_and_execute("show run") show_run = self.clean_input_data(show_run) return show_run