pyeapiasync.eapilibasync

Provides asynchronous wrapper for eAPI calls

This module provides an asynchronous connection to eAPI by wrapping eAPI calls in an instance of AsyncConnection. The connection module provides an easy implementation for sending and receiving calls over eAPI using asyncio and aiohttp.

Attributes

DEFAULT_HTTP_PORT

DEFAULT_HTTPS_PORT

DEFAULT_HTTP_LOCAL_PORT

DEFAULT_HTTPS_LOCAL_PORT

DEFAULT_HTTP_PATH

DEFAULT_UNIX_SOCKET

Exceptions

EapiError

Base exception class for all exceptions generated by eapilib

CommandError

Base exception raised for command errors

ConnectionError

Base exception raised for connection errors

Classes

EapiAsyncConnection

Creates an asynchronous connection to eAPI for sending and receiving

HttpLocalEapiAsyncConnection

Creates an asynchronous connection to eAPI for sending and receiving

HttpEapiAsyncConnection

Creates an asynchronous connection to eAPI for sending and receiving

HttpsEapiAsyncConnection

Creates an asynchronous connection to eAPI for sending and receiving

HttpsEapiCertAsyncConnection

Creates an asynchronous connection to eAPI for sending and receiving

SessionApiAsyncConnection

HttpEapiSessionAsyncConnection

Creates an asynchronous connection to eAPI for sending and receiving

HttpsEapiSessionAsyncConnection

Creates an asynchronous connection to eAPI for sending and receiving

SocketEapiAsyncConnection

Creates an asynchronous connection to eAPI for sending and receiving

Module Contents

pyeapiasync.eapilibasync.DEFAULT_HTTP_PORT = 80[source]
pyeapiasync.eapilibasync.DEFAULT_HTTPS_PORT = 443[source]
pyeapiasync.eapilibasync.DEFAULT_HTTP_LOCAL_PORT = 8080[source]
pyeapiasync.eapilibasync.DEFAULT_HTTPS_LOCAL_PORT = 8443[source]
pyeapiasync.eapilibasync.DEFAULT_HTTP_PATH = '/command-api'[source]
pyeapiasync.eapilibasync.DEFAULT_UNIX_SOCKET = '/var/run/command-api.sock'[source]
class pyeapiasync.eapilibasync.EapiAsyncConnection[source]

Bases: object

Creates an asynchronous connection to eAPI for sending and receiving eAPI requests

The EapiAsyncConnection object provides an implementation for sending and receiving eAPI requests and responses asynchronously using asyncio and aiohttp.

transport = None[source]
error = None[source]
socket_error = None[source]
authentication(username, password)[source]

Configures the user authentication for eAPI

This method configures the username and password combination to use for authenticating to eAPI.

Parameters:
  • username (str) – The username to use to authenticate the eAPI connection with

  • password (str) – The password in clear text to use to authenticate the eAPI connection with

request(commands, encoding=None, reqid=None, **kwargs)[source]

Generates an eAPI request object

This method will take a list of EOS commands and generate a valid eAPI request object form them. The eAPI request object is then JSON encoding and returned to the caller.

eAPI Request Object

{
    "jsonrpc": "2.0",
    "method": "runCmds",
    "params": {
        "version": 1,
        "cmds": [
            <commands>
        ],
        "format": [json, text],
    }
    "id": <reqid>
}
Parameters:
  • commands (list) – A list of commands to include in the eAPI request object

  • encoding (string) – The encoding method passed as the format parameter in the eAPI request

  • reqid (string) – A custom value to assign to the request ID field. This value is automatically generated if not passed

  • **kwargs – Additional keyword arguments for expanded eAPI functionality. Only supported eAPI params are used in building the request

Returns:

A JSON encoding request structure that can be send over eAPI

async send(data)[source]

Sends the eAPI request to the destination node asynchronously

This method is responsible for sending an eAPI request to the destination node and returning a response based on the eAPI response object. eAPI responds to request messages with either a success message or failure message.

Parameters:

data (string) – The data to be included in the body of the eAPI request object

Returns:

A decoded response. The response object is deserialized from

JSON and returned as a standard Python dictionary object

Raises:

CommandError if an eAPI failure response object is returned from – the node. The CommandError exception includes the error code and error message from the eAPI response.

async execute(commands, encoding='json', **kwargs)[source]

Executes the list of commands on the destination node asynchronously

This method takes a list of commands and sends them to the destination node, returning the results. The execute method handles putting the destination node in enable mode and will pass the enable password, if required.

Parameters:
  • commands (list) – A list of commands to execute on the remote node

  • encoding (string) – The encoding to send along with the request message to the destination node. Valid values include ‘json’ or ‘text’. This argument will influence the response object encoding

  • **kwargs – Arbitrary keyword arguments

Returns:

A decoded response message as a native Python dictionary object that has been deserialized from JSON.

Raises:

CommandError – A CommandError is raised that includes the error code, error message along with the list of commands that were sent to the node. The exception instance is also stored in the error property and is availble until the next request is sent

class pyeapiasync.eapilibasync.HttpLocalEapiAsyncConnection(port=None, path=None, timeout=60, **kwargs)[source]

Bases: EapiAsyncConnection

Creates an asynchronous connection to eAPI for sending and receiving eAPI requests

The EapiAsyncConnection object provides an implementation for sending and receiving eAPI requests and responses asynchronously using asyncio and aiohttp.

url = 'http://localhost:8080/command-api'[source]
ssl_context = None[source]
class pyeapiasync.eapilibasync.HttpEapiAsyncConnection(host, port=None, path=None, username=None, password=None, timeout=60, **kwargs)[source]

Bases: EapiAsyncConnection

Creates an asynchronous connection to eAPI for sending and receiving eAPI requests

The EapiAsyncConnection object provides an implementation for sending and receiving eAPI requests and responses asynchronously using asyncio and aiohttp.

url = 'http://Uninferable:80/command-api'[source]
ssl_context = None[source]
class pyeapiasync.eapilibasync.HttpsEapiAsyncConnection(host, port=None, path=None, username=None, password=None, context=None, timeout=60, **kwargs)[source]

Bases: EapiAsyncConnection

Creates an asynchronous connection to eAPI for sending and receiving eAPI requests

The EapiAsyncConnection object provides an implementation for sending and receiving eAPI requests and responses asynchronously using asyncio and aiohttp.

url = 'https://Uninferable:443/command-api'[source]
disable_certificate_verification()[source]
class pyeapiasync.eapilibasync.HttpsEapiCertAsyncConnection(host, port=None, path=None, key_file=None, cert_file=None, ca_file=None, timeout=60, **kwargs)[source]

Bases: EapiAsyncConnection

Creates an asynchronous connection to eAPI for sending and receiving eAPI requests

The EapiAsyncConnection object provides an implementation for sending and receiving eAPI requests and responses asynchronously using asyncio and aiohttp.

url = 'https://Uninferable:443/command-api'[source]
ssl_context[source]
class pyeapiasync.eapilibasync.SessionApiAsyncConnection[source]

Bases: object

async authentication(username, password)[source]
class pyeapiasync.eapilibasync.HttpEapiSessionAsyncConnection(host, port=None, path=None, username=None, password=None, timeout=60, **kwargs)[source]

Bases: SessionApiAsyncConnection, HttpEapiAsyncConnection

Creates an asynchronous connection to eAPI for sending and receiving eAPI requests

The EapiAsyncConnection object provides an implementation for sending and receiving eAPI requests and responses asynchronously using asyncio and aiohttp.

class pyeapiasync.eapilibasync.HttpsEapiSessionAsyncConnection(host, port=None, path=None, username=None, password=None, context=None, timeout=60, **kwargs)[source]

Bases: SessionApiAsyncConnection, HttpsEapiAsyncConnection

Creates an asynchronous connection to eAPI for sending and receiving eAPI requests

The EapiAsyncConnection object provides an implementation for sending and receiving eAPI requests and responses asynchronously using asyncio and aiohttp.

class pyeapiasync.eapilibasync.SocketEapiAsyncConnection(path=None, timeout=60, **kwargs)[source]

Bases: EapiAsyncConnection

Creates an asynchronous connection to eAPI for sending and receiving eAPI requests

The EapiAsyncConnection object provides an implementation for sending and receiving eAPI requests and responses asynchronously using asyncio and aiohttp.

path = '/var/run/command-api.sock'[source]
timeout = 60[source]
transport = 'socket'[source]
reader = None[source]
writer = None[source]
async send(data)[source]

Sends the eAPI request through a Unix socket asynchronously

Parameters:

data (string) – The data to be included in the body of the eAPI request object

Returns:

A decoded response from the Unix socket as a native Python dictionary

Raises:
exception pyeapiasync.eapilibasync.EapiError(message, commands=None)[source]

Bases: Exception

Base exception class for all exceptions generated by eapilib

This is the base exception class for all exceptions generated by eapilib. It is provided as a catch all for exceptions and should not be directly raised by an methods or functions

Parameters:
  • commands (array) – The list of commands there were sent to the node that when the exception was raised

  • message (string) – The exception error message

message[source]
commands = None[source]
exception pyeapiasync.eapilibasync.CommandError(code, message, **kwargs)[source]

Bases: EapiError

Base exception raised for command errors

The CommandError instance provides a custom exception that can be used if the eAPI command(s) fail. It provides some additional information that can be used to understand what caused the exception.

Parameters:
  • error_code (int) – The error code returned from the eAPI call.

  • error_text (string) – The error text message that coincides with the error_code

  • commands (array) – The list of commands that were sent to the node that generated the error

  • message (string) – The exception error message which is a concatenation of the error_code and error_text

error_code[source]
error_text[source]
command_error[source]
commands[source]
output[source]
message[source]
property trace[source]
get_trace()[source]
exception pyeapiasync.eapilibasync.ConnectionError(connection_type, message, commands=None)[source]

Bases: EapiError

Base exception raised for connection errors

Connection errors are raised when a connection object is unable to connect to the node. Typically these errors can result from using the wrong transport type or not providing valid credentials.

Parameters:
  • commands (array) – The list of commands there were sent to the node that when the exception was raised

  • connection_type (string) – The string identifier for the connection object that generate the error

  • message (string) – The exception error message

  • response (string) – The message generate from the response packet

message[source]
connection_type[source]
commands = None[source]