How to use the nornir.plugins.tasks.networking.netmiko_file_transfer function in nornir

To help you get started, we’ve selected a few nornir examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github twin-bridges / nornir_course / class4 / collateral / netmiko_file_copy / test_get.py View on Github external
def file_copy(task):
    # Obtain the group_name
    group_name = task.host.groups[0]

    # Set the filename based on the platform (ios, eos, et cetera)
    source_file = "test_file1.txt"
    dest_file = f"{group_name}/test_new.txt"

    # Transfer the file
    results = task.run(
        netmiko_file_transfer,
        source_file=source_file,
        dest_file=dest_file,
        direction="get",
    )

    print()
    print("-" * 40)
    print(task.host)
    print(source_file)
    print()
    if results[0].changed is False:
        print("File not transferred: correct local file already exists")
    else:
        print("File downloaded")

    if results[0].result is True:
github twin-bridges / nornir_course / class4 / collateral / netmiko_file_copy / test_copy1.py View on Github external
def file_copy(task):
    # Obtain the group_name
    group_name = task.host.groups[0]

    # Set the filename based on the platform (ios, eos, et cetera)
    base_file = "test_file1.txt"
    source_file = f"{group_name}/{base_file}"
    dest_file = base_file
    # print(source_file)

    # Transfer the file
    results = task.run(
        netmiko_file_transfer,
        source_file=source_file,
        dest_file=dest_file,
        direction="put",
    )

    print()
    print("-" * 40)
    print(task.host)
    if results[0].changed is False:
        print("File not transferred: correct file is already on the device")

    if results[0].result is True:
        print("Remote file exists and is correct")
    print("-" * 40)
    print()
github nornir-automation / nornir / tests / plugins / tasks / networking / test_netmiko_file_transfer.py View on Github external
def test_netmiko_file_transfer(self, nornir):
        source_file = os.path.join(THIS_DIR, "data", "test_file.txt")
        dest_file = "test_file.txt"
        result = nornir.filter(name="dev4.group_2").run(
            networking.netmiko_file_transfer,
            source_file=source_file,
            dest_file=dest_file,
            direction="put",
        )
        assert result
        for h, r in result.items():
            assert r.result
            assert r.changed
github ktbyers / pynet / nornir / os_upgrade / part2 / set_boot_var / nornir_os_upgrade.py View on Github external
def os_upgrade(task):
    file_name = task.host.get('img')
    task.run(
        task=netmiko_file_transfer,
        source_file=file_name,
        dest_file=file_name,
        direction='put',
    )
    return ""
github ktbyers / pynet / nornir / os_upgrade / part2 / netmiko_file_transfer_4.py View on Github external
def os_upgrade(task):
    file_name = task.host.get('img')
    task.run(
        task=netmiko_file_transfer,
        source_file=file_name,
        dest_file=file_name,
        direction='put',
    )
    return ''
github twin-bridges / nornir_course / class4 / exercises / exercise2 / exercise2a.py View on Github external
def file_copy(task):
    host = task.host
    platform = host.platform
    filename = host["file_name"]
    source_file = f"{platform}/{filename}"
    task.run(
        task=networking.netmiko_file_transfer,
        source_file=source_file,
        dest_file=filename,
        direction="put",
        overwrite_file=True,
    )
github ktbyers / pynet / nornir / os_upgrade / part2 / expanded_file_transfer / nornir_os_upgrade.py View on Github external
def os_upgrade(task):
    file_name = task.host.get('img')
    result = task.run(
        task=netmiko_file_transfer,
        source_file=file_name,
        dest_file=file_name,
        direction='put',
    )
    return result
github ktbyers / pynet / nornir / os_upgrade / part2 / reload / nornir_os_upgrade.py View on Github external
def os_upgrade(task):
    file_name = task.host.get('img')
    task.run(
        task=netmiko_file_transfer,
        source_file=file_name,
        dest_file=file_name,
        direction='put',
    )
    return ""
github twin-bridges / nornir_course / class4 / exercises / exercise2 / exercise2c.py View on Github external
def file_copy(task):
    host = task.host
    platform = host.platform
    filename = host["file_name"]
    dest_file = f"{platform}/{host.name}-saved.txt"
    multi_result = task.run(
        task=networking.netmiko_file_transfer,
        source_file=filename,
        dest_file=dest_file,
        direction="get",
        overwrite_file=True,
    )
    if multi_result[0].result is True:
        return f"SCP get completed: {dest_file}"
    else:
        return f"Failure...SCP get failed!!!"
github ktbyers / pynet / nornir / os_upgrade / part2 / netmiko_file_transfer_2.py View on Github external
def os_upgrade(task):
    file_name = task.host.get('img')
    result = task.run(
        task=netmiko_file_transfer,
        source_file=file_name,
        dest_file=file_name,
        direction='put',
    )
    return result