Ejemplo n.º 1
0
def main():
    """Connect to an IOSXRDevice and acquiring/validating an exclusive configuration session"""
    configs = ["do show configuration sessions"]
    with IOSXRDriver(**MY_DEVICE) as conn:
        # make sure you check the names of the privilege levels to know which one to use, in the
        # case of IOSXR we want "configuration_exclusive" for this example
        result = conn.send_configs(configs=configs, privilege_level="configuration_exclusive")

    # note the "*" in the "Lock" column indicates we acquired the exclusive config session
    print(result[0].result)
Ejemplo n.º 2
0
def test_commandeer(sync_driver):
    """
    Test commandeer works as expected
    """
    on_open_called = False

    def on_open(cls):
        nonlocal on_open_called
        on_open_called = True

    channel_log_dummy = BytesIO()
    sync_driver.channel.channel_log = channel_log_dummy

    new_conn = IOSXRDriver(host="tacocat", on_open=on_open)
    new_conn.commandeer(sync_driver, execute_on_open=True)

    assert on_open_called is True
    assert new_conn.transport is sync_driver.transport
    assert new_conn.channel.transport is sync_driver.transport
    assert new_conn.logger is sync_driver.logger
    assert new_conn.transport.logger is sync_driver.transport.logger
    assert new_conn.channel.logger is sync_driver.channel.logger
    assert new_conn.channel.channel_log is channel_log_dummy
Ejemplo n.º 3
0
    "auth_username": "******",
    "auth_password": "******",
    "auth_strict_key": False
}, {
    "host": "sbx-iosxr-mgmt.cisco.com",
    "auth_username": "******",
    "auth_password": "******",
    "port": 8181,
    "auth_strict_key": False
}]

os.system("clear")

conn_XE = IOSXEDriver(**devices[0])
conn_XE.open()
response = conn_XE.send_command("show ip int brief")
print("RESPONSE")
print("*" * 100)
print(response.result)
conn_XE.close()

conn_XR = IOSXRDriver(**devices[1])
conn_XR.open()
response = conn_XR.send_command("show ip int brief")

print("RESPONSE")
print("*" * 100)
# print(response.result)
# print(re.findall("Giga.+", response.result))
print(json.dumps(re.findall("Giga.+", response.result), indent=2))
conn_XR.close()
Ejemplo n.º 4
0
import logging
import time
from pathlib import Path

from device_info import iosxr_device
from scrapli.driver.core import IOSXRDriver

logging.basicConfig(
    filename=f"{Path(__file__).resolve().parents[0]}/iosxr_driver.log", level=logging.DEBUG
)
logger = logging.getLogger("scrapli")

conn = IOSXRDriver(**iosxr_device)
conn.open()

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

print("***** Show run | i hostname:")
result = conn.send_command("show run | i hostname")
print(result, result.result)

print("***** Show run:")
result = conn.send_command("show run")
print(result, result.result)

if iosxr_device["keepalive"]:
    print("***** Waiting for keepalive....")
    time.sleep(5)
Ejemplo n.º 5
0
if __name__ == '__main__':
    devices = [{
        'host': 'ios-xe-mgmt-latest.cisco.com',
        'auth_username': '******',
        'auth_password': '******',
        'auth_strict_key': False
    }, {
        'host': 'ios-xe-mgmt.cisco.com',
        'auth_username': '******',
        'auth_password': '******',
        'port': 8181,
        'ssh_config_file': '~/.ssh/config',
        # "transport_options": {"open_cmd": ["-o", "KexAlgorithms=+diffie-hellman-group14-sha1"]},
        'auth_strict_key': False
    }, {
        'host': 'sbx-iosxr-mgmt.cisco.com',
        'auth_username': '******',
        'auth_password': '******',
        'port': 8181,
        'auth_strict_key': False
    }]

    for i in devices:
        cmd = ''
        if 'xe' in i['host']:
            cmd = CiscoScrape(IOSXEDriver(**i), 'switch').write()
        elif 'xr' in i['host']:
            cmd = CiscoScrape(IOSXRDriver(**i), 'router').write()
        print(cmd)