eapi¶
EOS eAPI interaction module. This module allows interaction with the CLI via eAPI command requests. This allows EOS SDK applications access to configuration and status of EOS state for which EOS SDK APIs do not yet exist. Note that each method is a synchronous call, and opens a unix-domain socket. Therefore, this is not intended to be a replacement for other EosSdk modules.
For more information about eAPI, please visit https://eos.arista.com/arista-eapi-101/
The following snippet shows how to load an eAPI response into a json_t object from the jansson library, although any json library to convert from json-formatted text will do. Based on the jansson library documentation: https://jansson.readthedocs.io/en/2.10/tutorial.html
eapi_response_t show_interfaces = eapiMgr->run_show_cmd("show interfaces");
json_t* root;
json_error_t error;
if (show_interfaces.success()) {
root = json_loads(show_interfaces.responses()[0], 0, &error);
}
if (!root) {
fprintf(stderr, "error: on line %d: %s\n", error.line, error.text);
}
json_t* interfaces = json_object_get(root, "interfaces");
json_t* intf1 = json_object_get(interfaces, "Ethernet1");
json_t* desc1 = json_object_get(intf1, "description");
printf("Ethernet1's description: " << json_string_value(desc1));
...
-
namespace
eos
-
class
eapi_mgr
- #include <eapi.h>
eAPI manager.
Public Functions
-
virtual
~eapi_mgr
()
-
virtual eapi_response_t
run_show_cmd
(std::string const &) const = 0 Executes a “show” CLI command in enable mode.
-
virtual eapi_response_t
run_config_cmds
(std::vector< std::string > const &) const = 0 Executes one or many CLI commands in configuration mode.
Protected Functions
-
eapi_mgr
()
Private Members
-
eapi_mgr
-
virtual
-
class
Type definitions in eapi¶
-
namespace
eos
-
class
eapi_response_t
- #include <eapi.h>
An eAPI response from the Cli server.
Public Functions
-
eapi_response_t
() Default constructor.
-
eapi_response_t
(bool success, uint32_t error_code, std::string const & error_message, std::vector< std::string > const & responses) Full constructor.
-
eapi_response_t
(const eapi_response_t & other)
-
eapi_response_t &
operator=
(eapi_response_t const & other)
-
bool
success
() const Getter for ‘success’: indicates if a response was received.
-
uint32_t
error_code
() const Getter for ‘error_code’: error code from eAPI response.
-
std::string
error_message
() const Getter for ‘error_message’: error message from response.
-
std::vector< std::string > const &
responses
() const Getter for ‘responses’: the set of strings that constitute an eAPI response.
-
std::string
raw_response
() const Getter for ‘raw_response’: raw eAPI response (if requested).
-
std::string
to_string
() const Returns a string representation of the current object’s values.
Private Members
-
std::shared_ptr< eapi_response_impl_t >
pimpl
Friends
-
friend std::ostream &
operator<<
A utility stream operator that adds a string representation of eapi_response_t to the ostream.
-
-
class