File: generic_driver.py

package info (click to toggle)
python-scrapli 2023.7.30-4
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 4,508 kB
  • sloc: python: 14,451; makefile: 72
file content (34 lines) | stat: -rw-r--r-- 1,035 bytes parent folder | download | duplicates (3)
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
"""examples.basic_usage.generic_driver"""
from scrapli.driver import GenericDriver

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


def main():
    """Simple example of connecting to an IOSXEDevice with the GenericDriver"""
    # the `GenericDriver` is a good place to start if your platform is not supported by a "core"
    #  platform drivers
    conn = GenericDriver(**MY_DEVICE)
    conn.open()

    print(conn.channel.get_prompt())
    print(conn.send_command("show run | i hostname").result)

    # IMPORTANT: paging is NOT disabled w/ GenericDriver driver!
    conn.send_command("terminal length 0")
    print(conn.send_command("show run").result)
    conn.close()

    # Context manager is a great way to use scrapli, it will auto open/close the connection for you:
    with GenericDriver(**MY_DEVICE) as conn:
        result = conn.send_command("show run | i hostname")
    print(result.result)


if __name__ == "__main__":
    main()