ANTA Inventory API
AntaInventory
¶
Bases: dict[str, AntaDevice]
Inventory abstraction for ANTA framework.
add_device
¶
add_device(device: AntaDevice) -> None
Add a device to final inventory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
device
|
AntaDevice
|
Device object to be added. |
required |
Source code in anta/inventory/__init__.py
319 320 321 322 323 324 325 326 327 328 |
|
connect_inventory
async
¶
connect_inventory() -> None
Run refresh()
coroutines for all AntaDevice objects in this inventory.
Source code in anta/inventory/__init__.py
334 335 336 337 338 339 340 341 342 343 344 |
|
dump
¶
dump() -> AntaInventoryInput
Dump the AntaInventory to an AntaInventoryInput.
Each hosts is dumped individually.
Source code in anta/inventory/__init__.py
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
|
get_inventory
¶
get_inventory(
*,
established_only: bool = False,
tags: set[str] | None = None,
devices: set[str] | None = None
) -> AntaInventory
Return a filtered inventory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
established_only
|
bool
|
Whether or not to include only established devices. |
False
|
tags
|
set[str] | None
|
Tags to filter devices. |
None
|
devices
|
set[str] | None
|
Names to filter devices. |
None
|
Returns:
Type | Description |
---|---|
AntaInventory
|
An inventory with filtered AntaDevice objects. |
Source code in anta/inventory/__init__.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
|
parse
staticmethod
¶
parse(
filename: str | Path,
username: str,
password: str,
enable_password: str | None = None,
timeout: float | None = None,
file_format: Literal["yaml", "json"] = "yaml",
*,
enable: bool = False,
insecure: bool = False,
disable_cache: bool = False
) -> AntaInventory
Create an AntaInventory instance from an inventory file.
The inventory devices are AsyncEOSDevice instances.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str | Path
|
Path to device inventory YAML file. |
required |
username
|
str
|
Username to use to connect to devices. |
required |
password
|
str
|
Password to use to connect to devices. |
required |
enable_password
|
str | None
|
Enable password to use if required. |
None
|
timeout
|
float | None
|
Timeout value in seconds for outgoing API calls. |
None
|
file_format
|
Literal['yaml', 'json']
|
Whether the inventory file is in JSON or YAML. |
'yaml'
|
enable
|
bool
|
Whether or not the commands need to be run in enable mode towards the devices. |
False
|
insecure
|
bool
|
Disable SSH Host Key validation. |
False
|
disable_cache
|
bool
|
Disable cache globally. |
False
|
Raises:
Type | Description |
---|---|
InventoryRootKeyError
|
Root key of inventory is missing. |
InventoryIncorrectSchemaError
|
Inventory file is not following AntaInventory Schema. |
Source code in anta/inventory/__init__.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
|
AntaInventoryInput
¶
Bases: BaseModel
Device inventory input model.
to_json
¶
to_json() -> str
Return a JSON representation string of this model.
Returns:
Type | Description |
---|---|
The JSON representation string of this model.
|
|
Source code in anta/inventory/models.py
120 121 122 123 124 125 126 127 |
|
yaml
¶
yaml() -> str
Return a YAML representation string of this model.
Returns:
Type | Description |
---|---|
str
|
The YAML representation string of this model. |
Source code in anta/inventory/models.py
106 107 108 109 110 111 112 113 114 115 116 117 118 |
|
AntaInventoryHost
¶
Bases: AntaInventoryBaseModel
Host entry of AntaInventoryInput.
Attributes:
Name | Type | Description |
---|---|---|
host |
Hostname | IPvAnyAddress
|
IP Address or FQDN of the device. |
port |
Port | None
|
Custom eAPI port to use. |
name |
str | None
|
Custom name of the device. |
tags |
set[str]
|
Tags of the device. |
disable_cache |
bool
|
Disable cache for this device. |
AntaInventoryNetwork
¶
AntaInventoryRange
¶
Bases: AntaInventoryBaseModel
IP Range entry of AntaInventoryInput.
Attributes:
Name | Type | Description |
---|---|---|
start |
IPvAnyAddress
|
IPv4 or IPv6 address for the beginning of the range. |
stop |
IPvAnyAddress
|
IPv4 or IPv6 address for the end of the range. |
tags |
set[str]
|
Tags of the devices in this IP range. |
disable_cache |
bool
|
Disable cache for all devices in this IP range. |