Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def remove_ex2_flash_files():
# prep to ensure test files do not exist on devices
nornir_inventory = gen_inventory_dict("~/nornir_inventory/")
nr = InitNornir(inventory=nornir_inventory, logging=NORNIR_LOGGING)
eos = nr.filter(F(groups__contains="eos"))
# remove test files from eos flash
eos.run(task=networking.netmiko_send_command, command_string="terminal dont-ask")
eos.run(
task=networking.netmiko_send_command,
command_string="delete flash:arista_zzzzz.txt",
)
def test_negate_or_both_negate(self, nornir):
f = ~F(site="site1") | ~F(role="www")
filtered = sorted(list((nornir.inventory.filter(f).hosts.keys())))
assert filtered == [
"dev2.group_1",
"dev3.group_2",
"dev4.group_2",
"dev5.no_group",
]
def main():
nr = InitNornir(config_file="config.yaml")
nr = nr.filter(F(groups__contains="nxos"))
agg_result = nr.run(task=get_checkpoint_file)
print_result(agg_result)
def main():
nr = InitNornir(config_file="config.yaml")
nr = nr.filter(F(groups__contains="eos"))
result = nr.run(task=file_copy, num_workers=10)
print_result(result)
def main():
nr = InitNornir(config_file="config.yaml")
nr = nr.filter(F(groups__contains="eos"))
result = nr.run(task=file_copy)
print_result(result)
def main():
nr = InitNornir(config_file="config.yaml")
ios_filt = F(groups__contains="ios")
nr = nr.filter(ios_filt)
nr.inventory.hosts["cisco3"].password = "bogus"
my_results = nr.run(task=netmiko_send_command, command_string="show ip int brief")
print_result(my_results)
print()
print(f"Task failed hosts: {my_results.failed_hosts}")
print(f"Global failed hosts: {nr.data.failed_hosts}")
print()
def main():
LOGGER.info("Script initalizing...")
nr = InitNornir(config_file="config.yaml")
nr = nr.filter(F(groups__contains="eos"))
for hostname, host_obj in nr.inventory.hosts.items():
host_obj.password = PASSWORD
LOGGER.critical("Passwords set, commence automation!")
nr.run(
task=networking.netmiko_send_command, command_string="show mac address-table"
)
LOGGER.error("Oh no! We're all out of automation tasks :(")
LOGGER.debug("Hey, what are you still doing here?")
def main():
nr = InitNornir(config_file="config.yaml")
ios_filt = F(groups__contains="ios")
nr = nr.filter(ios_filt)
my_results = nr.run(task=netmiko_send_command, command_string="show ip int brief")
print_result(my_results)
print(arista1.inventory.hosts)
print("-" * 20)
print("\nExercise 2b")
print("-" * 20)
wan_devs = nr.filter(role="WAN")
print(wan_devs.inventory.hosts)
wan_devs = wan_devs.filter(port=22)
print(wan_devs.inventory.hosts)
print("-" * 20)
# Alternatively:
# wan_devs = nr.filter(role="WAN").filter(port=22)
print("\nExercise 2c")
print("-" * 20)
sfo_f_obj = nr.filter(F(groups__contains="sfo"))
print(sfo_f_obj.inventory.hosts)
print("-" * 20)
print()
def main():
# Exercise 4a
nr = InitNornir(config_file="config.yaml")
# Exercise 4b
nr = nr.filter(F(groups__contains="eos"))
agg_result = nr.run(
task=netmiko_send_command, command_string="show int status", use_textfsm=True
)
# Verify structured data (pick a device and check)
print()
print("Exercise 4b - verify structured data")
print("-" * 20)
print(type(agg_result["arista1"][0].result))
print("-" * 20)
print("\nExercise 4c - final dictionary")
print("-" * 20)
combined_data = {}
for device_name, multi_result in agg_result.items():
combined_data[device_name] = {}