ANTA is a Python library that can be used in user applications. This section describes how you can leverage ANTA Python modules to help you create your own NRFU solution.
Tip
If you are unfamiliar with asyncio, refer to the Python documentation relevant to your Python version - https://docs.python.org/3/library/asyncio.html
AntaDevice Abstract Class
A device is represented in ANTA as a instance of a subclass of the AntaDevice abstract class. There are few abstract methods that needs to be implemented by child classes:
- The collect() coroutine is in charge of collecting outputs of AntaCommand instances.
- The refresh() coroutine is in charge of updating attributes of the AntaDevice instance. These attributes are used by AntaInventory to filter out unreachable devices or by AntaTest to skip devices based on their hardware models.
The copy() coroutine is used to copy files to and from the device. It does not need to be implemented if tests are not using it.
AsyncEOSDevice Class
The AsyncEOSDevice class is an implementation of AntaDevice for Arista EOS. It uses the aio-eapi eAPI client and the AsyncSSH library.
- The _collect() coroutine collects AntaCommand outputs using eAPI.
- The refresh() coroutine tries to open a TCP connection on the eAPI port and update the
is_online
attribute accordingly. If the TCP connection succeeds, it sends ashow version
command to gather the hardware model of the device and updates theestablished
andhw_model
attributes. - The copy() coroutine copies files to and from the device using the SCP protocol.
AntaInventory Class
The AntaInventory class is a subclass of the standard Python type dict. The keys of this dictionary are the device names, the values are AntaDevice instances.
AntaInventory provides methods to interact with the ANTA inventory:
- The add_device() method adds an AntaDevice instance to the inventory. Adding an entry to AntaInventory with a key different from the device name is not allowed.
- The get_inventory() returns a new AntaInventory instance with filtered out devices based on the method inputs.
- The connect_inventory() coroutine will execute the refresh() coroutines of all the devices in the inventory.
- The parse() static method creates an AntaInventory instance from a YAML file and returns it. The devices are AsyncEOSDevice instances.
--8<-- "parse_anta_inventory_file.py"
Note
How to create your inventory file
Please visit this dedicated section for how to use inventory and catalog files.
--8<-- "run_eos_commands.py"