Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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:
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()
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
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 ""
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 ''
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,
)
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
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 ""
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!!!"
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