summaryrefslogtreecommitdiffstats
path: root/examples/parse_anta_inventory_file.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-10-15 20:30:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-10-15 20:30:44 +0000
commit4a398db99d88dd17dabc408fb2b58c610792bc1e (patch)
treee5404d6d19a4d67a9428b3d10f886717b9756352 /examples/parse_anta_inventory_file.py
parentAdding upstream version 1.0.0. (diff)
downloadanta-upstream.tar.xz
anta-upstream.zip
Adding upstream version 1.1.0.upstream/1.1.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'examples/parse_anta_inventory_file.py')
-rw-r--r--examples/parse_anta_inventory_file.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/examples/parse_anta_inventory_file.py b/examples/parse_anta_inventory_file.py
new file mode 100644
index 0000000..fbbe042
--- /dev/null
+++ b/examples/parse_anta_inventory_file.py
@@ -0,0 +1,34 @@
+# Copyright (c) 2024 Arista Networks, Inc.
+# Use of this source code is governed by the Apache License 2.0
+# that can be found in the LICENSE file.
+"""Script that parses an ANTA inventory file, connects to devices and print their status."""
+
+import asyncio
+
+from anta.inventory import AntaInventory
+
+
+async def main(inv: AntaInventory) -> None:
+ """Read an AntaInventory and try to connect to every device in the inventory.
+
+ Print a message for every device connection status
+ """
+ await inv.connect_inventory()
+
+ for device in inv.values():
+ if device.established:
+ print(f"Device {device.name} is online")
+ else:
+ print(f"Could not connect to device {device.name}")
+
+
+if __name__ == "__main__":
+ # Create the AntaInventory instance
+ inventory = AntaInventory.parse(
+ filename="inventory.yaml",
+ username="arista",
+ password="@rista123",
+ )
+
+ # Run the main coroutine
+ res = asyncio.run(main(inventory))