"""Quick Nornir check that mimics the validation playbook. Run with: python3 verify_paths.py """ from nornir import InitNornir from nornir_utils.plugins.functions import print_result from nornir_scrapli.tasks import send_command def check_ospf(task): result = task.run(task=send_command, command="show ip ospf neighbor") if task.host.get("expected_neighbors"): missing = [nbr for nbr in task.host.expected_neighbors if nbr not in result.result] if missing: result.failed = True result.result += f"\nMissing neighbors: {missing}" return result def check_bgp(task): return task.run(task=send_command, command="show bgp ipv4 unicast summary") def main(): nr = InitNornir(config_file="config.yaml") campus = nr.filter(groups__contains="campus") wan = nr.filter(groups__contains="wan") print_result(campus.run(task=check_ospf)) print_result(wan.run(task=check_bgp)) if __name__ == "__main__": main()