Adding upstream version 1.2.0.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
77504588ab
commit
6fd6eb426a
154 changed files with 7346 additions and 5000 deletions
|
@ -9,4 +9,4 @@ from .config_session import SessionConfig
|
|||
from .device import Device
|
||||
from .errors import EapiCommandError
|
||||
|
||||
__all__ = ["Device", "SessionConfig", "EapiCommandError"]
|
||||
__all__ = ["Device", "EapiCommandError", "SessionConfig"]
|
||||
|
|
|
@ -34,8 +34,7 @@ __all__ = ["port_check_url"]
|
|||
|
||||
|
||||
async def port_check_url(url: URL, timeout: int = 5) -> bool:
|
||||
"""
|
||||
Open the port designated by the URL given the timeout in seconds.
|
||||
"""Open the port designated by the URL given the timeout in seconds.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
|
|
@ -29,8 +29,7 @@ __all__ = ["SessionConfig"]
|
|||
|
||||
|
||||
class SessionConfig:
|
||||
"""
|
||||
Send configuration to a device using the EOS session mechanism.
|
||||
"""Send configuration to a device using the EOS session mechanism.
|
||||
|
||||
This is the preferred way of managing configuration changes.
|
||||
|
||||
|
@ -44,8 +43,7 @@ class SessionConfig:
|
|||
CLI_CFG_FACTORY_RESET = "rollback clean-config"
|
||||
|
||||
def __init__(self, device: Device, name: str) -> None:
|
||||
"""
|
||||
Create a new instance of SessionConfig.
|
||||
"""Create a new instance of SessionConfig.
|
||||
|
||||
The session config instance bound
|
||||
to the given device instance, and using the session `name`.
|
||||
|
@ -81,8 +79,7 @@ class SessionConfig:
|
|||
# -------------------------------------------------------------------------
|
||||
|
||||
async def status_all(self) -> dict[str, Any]:
|
||||
"""
|
||||
Get the status of all the session config on the device.
|
||||
"""Get the status of all the session config on the device.
|
||||
|
||||
Run the following command on the device:
|
||||
# show configuration sessions detail
|
||||
|
@ -122,8 +119,7 @@ class SessionConfig:
|
|||
return await self._cli("show configuration sessions detail") # type: ignore[return-value] # json outformat returns dict[str, Any]
|
||||
|
||||
async def status(self) -> dict[str, Any] | None:
|
||||
"""
|
||||
Get the status of a session config on the device.
|
||||
"""Get the status of a session config on the device.
|
||||
|
||||
Run the following command on the device:
|
||||
# show configuration sessions detail
|
||||
|
@ -179,8 +175,7 @@ class SessionConfig:
|
|||
return res["sessions"].get(self.name)
|
||||
|
||||
async def push(self, content: list[str] | str, *, replace: bool = False) -> None:
|
||||
"""
|
||||
Send the configuration content to the device.
|
||||
"""Send the configuration content to the device.
|
||||
|
||||
If `replace` is true, then the command "rollback clean-config" is issued
|
||||
before sending the configuration content.
|
||||
|
@ -218,8 +213,7 @@ class SessionConfig:
|
|||
await self._cli(commands=commands)
|
||||
|
||||
async def commit(self, timer: str | None = None) -> None:
|
||||
"""
|
||||
Commit the session config.
|
||||
"""Commit the session config.
|
||||
|
||||
Run the following command on the device:
|
||||
# configure session <name>
|
||||
|
@ -241,8 +235,7 @@ class SessionConfig:
|
|||
await self._cli(command)
|
||||
|
||||
async def abort(self) -> None:
|
||||
"""
|
||||
Abort the configuration session.
|
||||
"""Abort the configuration session.
|
||||
|
||||
Run the following command on the device:
|
||||
# configure session <name> abort
|
||||
|
@ -250,8 +243,7 @@ class SessionConfig:
|
|||
await self._cli(f"{self._cli_config_session} abort")
|
||||
|
||||
async def diff(self) -> str:
|
||||
"""
|
||||
Return the "diff" of the session config relative to the running config.
|
||||
"""Return the "diff" of the session config relative to the running config.
|
||||
|
||||
Run the following command on the device:
|
||||
# show session-config named <name> diffs
|
||||
|
@ -268,8 +260,7 @@ class SessionConfig:
|
|||
return await self._cli(f"show session-config named {self.name} diffs", ofmt="text") # type: ignore[return-value] # text outformat returns str
|
||||
|
||||
async def load_file(self, filename: str, *, replace: bool = False) -> None:
|
||||
"""
|
||||
Load the configuration from <filename> into the session configuration.
|
||||
"""Load the configuration from <filename> into the session configuration.
|
||||
|
||||
If the replace parameter is True then the file contents will replace the existing session config (load-replace).
|
||||
|
||||
|
|
|
@ -43,8 +43,7 @@ __all__ = ["Device"]
|
|||
|
||||
|
||||
class Device(httpx.AsyncClient):
|
||||
"""
|
||||
Represent the async JSON-RPC client that communicates with an Arista EOS device.
|
||||
"""Represent the async JSON-RPC client that communicates with an Arista EOS device.
|
||||
|
||||
This class inherits directly from the
|
||||
httpx.AsyncClient, so any initialization options can be passed directly.
|
||||
|
@ -63,8 +62,7 @@ class Device(httpx.AsyncClient):
|
|||
port: str | int | None = None,
|
||||
**kwargs: Any, # noqa: ANN401
|
||||
) -> None:
|
||||
"""
|
||||
Initialize the Device class.
|
||||
"""Initialize the Device class.
|
||||
|
||||
As a subclass to httpx.AsyncClient, the caller can provide any of those initializers.
|
||||
Specific parameters for Device class are all optional and described below.
|
||||
|
@ -111,8 +109,7 @@ class Device(httpx.AsyncClient):
|
|||
self.headers["Content-Type"] = "application/json-rpc"
|
||||
|
||||
async def check_connection(self) -> bool:
|
||||
"""
|
||||
Check the target device to ensure that the eAPI port is open and accepting connections.
|
||||
"""Check the target device to ensure that the eAPI port is open and accepting connections.
|
||||
|
||||
It is recommended that a Caller checks the connection before involving cli commands,
|
||||
but this step is not required.
|
||||
|
@ -124,7 +121,7 @@ class Device(httpx.AsyncClient):
|
|||
"""
|
||||
return await port_check_url(self.base_url)
|
||||
|
||||
async def cli( # noqa: PLR0913
|
||||
async def cli(
|
||||
self,
|
||||
command: str | dict[str, Any] | None = None,
|
||||
commands: Sequence[str | dict[str, Any]] | None = None,
|
||||
|
@ -136,8 +133,7 @@ class Device(httpx.AsyncClient):
|
|||
expand_aliases: bool = False,
|
||||
req_id: int | str | None = None,
|
||||
) -> list[dict[str, Any] | str] | dict[str, Any] | str | None:
|
||||
"""
|
||||
Execute one or more CLI commands.
|
||||
"""Execute one or more CLI commands.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
@ -199,7 +195,7 @@ class Device(httpx.AsyncClient):
|
|||
return None
|
||||
raise
|
||||
|
||||
def _jsonrpc_command( # noqa: PLR0913
|
||||
def _jsonrpc_command(
|
||||
self,
|
||||
commands: Sequence[str | dict[str, Any]] | None = None,
|
||||
ofmt: str | None = None,
|
||||
|
@ -264,8 +260,7 @@ class Device(httpx.AsyncClient):
|
|||
return cmd
|
||||
|
||||
async def jsonrpc_exec(self, jsonrpc: dict[str, Any]) -> list[dict[str, Any] | str]:
|
||||
"""
|
||||
Execute the JSON-RPC dictionary object.
|
||||
"""Execute the JSON-RPC dictionary object.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
|
|
@ -12,8 +12,7 @@ import httpx
|
|||
|
||||
|
||||
class EapiCommandError(RuntimeError):
|
||||
"""
|
||||
Exception class for EAPI command errors.
|
||||
"""Exception class for EAPI command errors.
|
||||
|
||||
Attributes
|
||||
----------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue