Пример #1
0
from scrapli.driver.core import IOSXEDriver

device = {
    "host": "ios-xe-mgmt-latest.cisco.com",
    "auth_username": "******",
    "auth_password": "******",
    "port": 8181,
    "auth_strict_key": False,
}

conn = IOSXEDriver(**device)
conn.open()
responses = conn.send_commands(["show version", "show ip int brief"])

for response in responses:
    print("RESPONSE")
    print("*" * 100)
    print(response.result)
conn.close()
Пример #2
0
    "port": device["port"],
    "ssh_config_file": True,
    "auth_strict_key": False,
    "keepalive_interval": device["keepalive_interval"],
    "transport": device["transport"],
    "keepalive": device["keepalive"],
}

conn = IOSXEDriver(**args)
conn.open()

print("***** Get Prompt:")
print(conn.get_prompt())

print("***** Show run | i hostname:")
result = conn.send_commands("show run | i hostname")
print(result, result[0].result)

print("***** Clear logging buffer:")
interact = [("clear logg", "Clear logging buffer [confirm]"), ("", "3560CX#")]
result = conn.send_interactive(interact)
print(result, result[0].result)

print("***** Disable Paging:")
result = conn.send_commands("term length 0")
print(result, result[0].result)

print("***** Show run:")
result = conn.send_commands("show run")
print(result, result[0].result)
Пример #3
0
# For each device loaded from the input file, populate a dictionary object with connection details
for ip_addr in devices:
    my_device = {
        "host": ip_addr,
        "auth_username": UNAME,
        "auth_password": PWORD,
        "auth_secondary": PWORD,
        "auth_strict_key": False,
        "transport": "paramiko"
    }

    # Create and open the connection object, send the list of commands and store the responses
    conn = IOSXEDriver(**my_device)
    conn.open()
    response = conn.send_commands(commands)

    # Extract the result of the first command - this should be the hostname
    hostname = response.data[0].result

    # Create a variable to store the heading (hostname & IP) formatted nicely
    data = "\n" + "=" * 85 + "\n" + hostname + ", Mngt IP: " + ip_addr + "\n" + "=" * 85 + "\n"

    # For each command loaded from commands.txt, loop through each command and add the command output to the data variable
    for command in response.data:
        # We don't want to do this for if the output contains 'hostname'
        if "hostname" not in command.result:
            # Append the command result
            data = data + command.result + "\n"

    # Open the output file and write the data for this device before looping around for the next device