File: scrapli_driver.py

package info (click to toggle)
python-scrapli 2023.7.30-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,512 kB
  • sloc: python: 14,451; makefile: 72
file content (35 lines) | stat: -rw-r--r-- 1,106 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
"""examples.basic_usage.scrapli_driver"""
from scrapli import Driver

MY_DEVICE = {
    "host": "172.18.0.11",
    "auth_username": "scrapli",
    "auth_password": "scrapli",
    "auth_strict_key": False,
}


def main():
    """Example demonstrating using the `Driver` driver directly"""
    # the `Driver` 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 `Driver` as a last resort!
    conn = Driver(**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 Driver(**MY_DEVICE) as conn:
        result = conn.channel.send_input("show run | i hostname")
    print(result[1])


if __name__ == "__main__":
    main()