Debian Codegraph @

examples/parse_anta_inventory_file.py

raw symbols SCIP
1 # Copyright (c) 2024 Arista Networks, Inc.
2 # Use of this source code is governed by the Apache License 2.0
3 # that can be found in the LICENSE file.
4 """Script that parses an ANTA inventory file, connects to devices and print their status."""
5
6 import asyncio
7
8 from anta.inventory import AntaInventory
9
10
11 async def main(inv: AntaInventory) -> None:
12 """Read an AntaInventory and try to connect to every device in the inventory.
13
14 Print a message for every device connection status
15 """
16 await inv.connect_inventory()
17
18 for device in inv.values():
19 if device.established:
20 print(f"Device {device.name} is online")
21 else:
22 print(f"Could not connect to device {device.name}")
23
24
25 if __name__ == "__main__":
26 # Create the AntaInventory instance
27 inventory = AntaInventory.parse(
28 filename="inventory.yaml",
29 username="arista",
30 password="@rista123",
31 )
32
33 # Run the main coroutine
34 res = asyncio.run(main(inventory))