ANTA Commands API
AntaCommand
¶
Bases: BaseModel
Class to define a command.
Info
eAPI models are revisioned, this means that if a model is modified in a non-backwards compatible way, then its revision will be bumped up (revisions are numbers, default value is 1).
By default an eAPI request will return revision 1 of the model instance, this ensures that older management software will not suddenly stop working when a switch is upgraded. A revision applies to a particular CLI command whereas a version is global and is internally translated to a specific revision for each CLI command in the RPC.
Revision has precedence over version.
Attributes:
Name | Type | Description |
---|---|---|
command |
str
|
Device command. |
version |
Literal[1, 'latest']
|
eAPI version - valid values are 1 or “latest”. |
revision |
Revision | None
|
eAPI revision of the command. Valid values are 1 to 99. Revision has precedence over version. |
ofmt |
Literal['json', 'text']
|
eAPI output - json or text. |
output |
dict[str, Any] | str | None
|
Output of the command. Only defined if there was no errors. |
template |
AntaTemplate | None
|
AntaTemplate object used to render this command. |
errors |
list[str]
|
If the command execution fails, eAPI returns a list of strings detailing the error(s). |
params |
AntaParamsBaseModel
|
Pydantic Model containing the variables values used to render the template. |
use_cache |
bool
|
Enable or disable caching for this AntaCommand if the AntaDevice supports it. |
collected
property
¶
collected: bool
Return True if the command has been collected, False otherwise.
A command that has not been collected could have returned an error. See error property.
requires_privileges
property
¶
requires_privileges: bool
Return True if the command requires privileged mode, False otherwise.
Raises:
Type | Description |
---|---|
RuntimeError
|
If the command has not been collected and has not returned an error. AntaDevice.collect() must be called before this property. |
returned_known_eos_error
property
¶
returned_known_eos_error: bool
Return True if the command returned a known_eos_error on the device, False otherwise.
RuntimeError If the command has not been collected and has not returned an error. AntaDevice.collect() must be called before this property.
supported
property
¶
supported: bool
Indicates if the command is supported on the device.
Returns:
Type | Description |
---|---|
bool
|
True if the command is supported on the device hardware platform, False otherwise. |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the command has not been collected and has not returned an error. AntaDevice.collect() must be called before this property. |
AntaTemplate
¶
AntaTemplate(
template: str,
version: Literal[1, "latest"] = "latest",
revision: Revision | None = None,
ofmt: Literal["json", "text"] = "json",
*,
use_cache: bool = True
)
Class to define a command template as Python f-string.
Can render a command from parameters.
Attributes:
Name | Type | Description |
---|---|---|
template |
Python f-string. Example: ‘show vlan {vlan_id}’. |
|
version |
eAPI version - valid values are 1 or “latest”. |
|
revision |
Revision of the command. Valid values are 1 to 99. Revision has precedence over version. |
|
ofmt |
eAPI output - json or text. |
|
use_cache |
Enable or disable caching for this AntaTemplate if the AntaDevice supports it. |
render
¶
render(**params: str | int | bool) -> AntaCommand
Render an AntaCommand from an AntaTemplate instance.
Keep the parameters used in the AntaTemplate instance.
Parameters:
Returns:
Type | Description |
---|---|
AntaCommand
|
The rendered AntaCommand. This AntaCommand instance have a template attribute that references this AntaTemplate instance. |
Raises:
Type | Description |
---|---|
AntaTemplateRenderError
|
If a parameter is missing to render the AntaTemplate instance. |
Source code in anta/models.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
EOS Commands Error Handling¶
UNSUPPORTED_PLATFORM_ERRORS
¶UNSUPPORTED_PLATFORM_ERRORS = [
"not supported on this hardware platform",
"Invalid input (at token 2: 'trident')",
]
Error messages indicating platform or hardware unsupported commands. Includes both general hardware platform errors and specific ASIC family limitations.
Running EOS commands unsupported by hardware
When catching these errors, ANTA will skip the affected test and raise a warning. The test catalog must be updated to remove execution of the affected test on unsupported devices.
EOS_BLACKLIST_CMDS
¶EOS_BLACKLIST_CMDS = ['^reload.*', '^conf.*', '^wr.*']
List of blacklisted EOS commands.
Disruptive commands safeguard
ANTA implements a mechanism to prevent the execution of disruptive commands such as reload
, write erase
or configure terminal
.
KNOWN_EOS_ERRORS
¶KNOWN_EOS_ERRORS = [
"BGP inactive",
"VRF '.*' is not active",
".* does not support IP",
"IS-IS (.*) is disabled because: .*",
"No source interface .*",
".*controller\\snot\\sready.*",
]
List of known EOS errors.
Generic EOS Error Handling
When catching these errors, ANTA will fail the affected test and reported the error message.