Device models
AntaDevice base class¶
UML representation¶
AntaDevice ¶
AntaDevice(name: str, tags: Optional[list[str]] = None)
Bases: ABC
Abstract class representing a device in ANTA.
An implementation of this class needs must override the abstract coroutines collect()
and
refresh()
.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
Device name |
is_online |
bool
|
True if the device IP is reachable and a port can be open |
established |
bool
|
True if remote command execution succeeds |
hw_model |
Optional[str]
|
Hardware model of the device |
tags |
list[str]
|
List of tags for this device |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
Device name |
required |
tags |
Optional[list[str]]
|
list of tags for this device |
None
|
Source code in anta/device.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
collect
abstractmethod
async
¶
collect(command: AntaCommand) -> None
Collect device command output. This abstract coroutine can be used to implement any command collection method for a device in ANTA.
The collect()
implementation needs to populate the output
attribute
of the AntaCommand
object passed as argument.
If a failure occurs, the collect()
implementation is expected to catch the
exception and implement proper logging, the output
attribute of the
AntaCommand
object passed as argument would be None
in this case.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command |
AntaCommand
|
the command to collect |
required |
Source code in anta/device.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
collect_commands
async
¶
collect_commands(commands: list[AntaCommand]) -> None
Collect multiple commands.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
commands |
list[AntaCommand]
|
the commands to collect |
required |
Source code in anta/device.py
95 96 97 98 99 100 101 102 |
|
copy
async
¶
copy(sources: list[Path], destination: Path, direction: Literal['to', 'from'] = 'from') -> None
Copy files to and from the device, usually through SCP. It is not mandatory to implement this for a valid AntaDevice subclass.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sources |
list[Path]
|
List of files to copy to or from the device. |
required |
destination |
Path
|
Local or remote destination when copying the files. Can be a folder. |
required |
direction |
Literal['to', 'from']
|
Defines if this coroutine copies files to or from the device. |
'from'
|
Source code in anta/device.py
115 116 117 118 119 120 121 122 123 124 125 |
|
refresh
abstractmethod
async
¶
refresh() -> None
Update attributes of an AntaDevice instance.
This coroutine must update the following attributes of AntaDevice
is_online
: When the device IP is reachable and a port can be openestablished
: When a command execution succeedshw_model
: The hardware model of the device
Source code in anta/device.py
104 105 106 107 108 109 110 111 112 113 |
|
Async EOS device class¶
UML representation¶
AsyncEOSDevice ¶
AsyncEOSDevice(host: str, username: str, password: str, name: Optional[str] = None, enable: bool = False, enable_password: Optional[str] = None, port: Optional[int] = None, ssh_port: Optional[int] = 22, tags: Optional[list[str]] = None, timeout: Optional[float] = None, insecure: bool = False, proto: Literal['http', 'https'] = 'https')
Bases: AntaDevice
Implementation of AntaDevice for EOS using aio-eapi.
Attributes:
Name | Type | Description |
---|---|---|
name |
Device name |
|
is_online |
True if the device IP is reachable and a port can be open |
|
established |
True if remote command execution succeeds |
|
hw_model |
Hardware model of the device |
|
tags |
List of tags for this device |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
host |
str
|
Device FQDN or IP |
required |
username |
str
|
Username to connect to eAPI and SSH |
required |
password |
str
|
Password to connect to eAPI and SSH |
required |
name |
Optional[str]
|
Device name |
None
|
enable |
bool
|
Device needs privileged access |
False
|
enable_password |
Optional[str]
|
Password used to gain privileged access on EOS |
None
|
port |
Optional[int]
|
eAPI port. Defaults to 80 is proto is ‘http’ or 443 if proto is ‘https’. |
None
|
ssh_port |
Optional[int]
|
SSH port |
22
|
tags |
Optional[list[str]]
|
List of tags for this device |
None
|
timeout |
Optional[float]
|
Timeout value in seconds for outgoing connections. Default to 10 secs. |
None
|
insecure |
bool
|
Disable SSH Host Key validation |
False
|
proto |
Literal['http', 'https']
|
eAPI protocol. Value can be ‘http’ or ‘https’ |
'https'
|
Source code in anta/device.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
|
collect
async
¶
collect(command: AntaCommand) -> None
Collect device command output from EOS using aio-eapi.
Supports outformat json
and text
as output structure.
Gain privileged access using the enable_password
attribute
of the AntaDevice
instance if populated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
command |
AntaCommand
|
the command to collect |
required |
Source code in anta/device.py
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 262 263 264 265 |
|
copy
async
¶
copy(sources: list[Path], destination: Path, direction: Literal['to', 'from'] = 'from') -> None
Copy files to and from the device using asyncssh.scp().
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sources |
list[Path]
|
List of files to copy to or from the device. |
required |
destination |
Path
|
Local or remote destination when copying the files. Can be a folder. |
required |
direction |
Literal['to', 'from']
|
Defines if this coroutine copies files to or from the device. |
'from'
|
Source code in anta/device.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 |
|
refresh
async
¶
refresh() -> None
Update attributes of an AsyncEOSDevice instance.
This coroutine must update the following attributes of AsyncEOSDevice: - is_online: When a device IP is reachable and a port can be open - established: When a command execution succeeds - hw_model: The hardware model of the device
Source code in anta/device.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
|