def main(): """Example demonstrating using the `Scrape` driver directly""" # the `Scrape` driver is only for use if you *really* want to manually handle the channel # input/output if your device type is supported by a core platform you should probably use that, # otherwise check out the `GenericDriver` before diving into `Scrape` as a last resort! conn = Scrape(**MY_DEVICE) conn.open() print(conn.channel.get_prompt()) print(conn.channel.send_input("show run | i hostname")[1]) # paging is NOT disabled w/ Scrape driver! conn.channel.send_input("terminal length 0") print(conn.channel.send_input("show run")[1]) conn.close() # Context manager is a great way to use scrapli: with Scrape(**MY_DEVICE) as conn: result = conn.channel.send_input("show run | i hostname") print(result[1])
import logging import time from pathlib import Path from device_info import iosxe_device from scrapli import Scrape logging.basicConfig( filename=f"{Path(__file__).resolve().parents[0]}/scrape_driver.log", level=logging.DEBUG ) logger = logging.getLogger("scrapli") conn = Scrape(**iosxe_device) conn.open() print("***** Get Prompt:") print(conn.channel.get_prompt()) print("***** Show run | i hostname:") result = conn.channel.send_input("show run | i hostname") print(result) print("***** Clear logging buffer:") interact = [("clear logg", "Clear logging buffer [confirm]"), ("", "csr1000v#")] result = conn.channel.send_inputs_interact(interact) print(result) print("***** Disable Paging:") result = conn.channel.send_input("term length 0") print(result)