| 1 |
|
| 2 |
|
| 3 |
|
| 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 |
|
| 27 |
inventory = AntaInventory.parse( |
| 28 |
filename="inventory.yaml", |
| 29 |
username="arista", |
| 30 |
password="@rista123", |
| 31 |
) |
| 32 |
|
| 33 |
|
| 34 |
res = asyncio.run(main(inventory)) |