The eAPI preparation

The eAPI agent on the Arista device is disabled by default, so we will need to enable it on the device before we can use it:

arista1(config)#management api http-commands
arista1(config-mgmt-api-http-cmds)#no shut
arista1(config-mgmt-api-http-cmds)#protocol https port 443
arista1(config-mgmt-api-http-cmds)#no protocol http
arista1(config-mgmt-api-http-cmds)#vrf management

As you can see, we have turned off HTTP server and use HTTPS as the transport instead. Starting from a few EOS version ago, the management interfaces is, by default, residing in a VRF called management. In my topology, I am accessing the device via the management interface; therefore, I have specified the VRF specifically. You can check that API management is turned on by the show command:

arista1#sh management api http-commands
Enabled: Yes
HTTPS server: running, set to use port 443
HTTP server: shutdown, set to use port 80
Local HTTP server: shutdown, no authentication, set to use port 8080
Unix Socket server: shutdown, no authentication
VRF: management
Hits: 64
Last hit: 33 seconds ago
Bytes in: 8250
Bytes out: 29862
Requests: 23
Commands: 42
Duration: 7.086 seconds
SSL Profile: none
QoS DSCP: 0
User Requests Bytes in Bytes out Last hit
----------- -------------- -------------- --------------- --------------
admin 23 8250 29862 33 seconds ago

URLs
-----------------------------------------
Management1 : https://192.168.199.158:443

arista1#

After enabling the agent, you will be able to access the exploration page for eAPI by going to the device's IP address. If you have changed the default port for access, just append it at the end. The authentication is tied in to the method of authentication on the switch; in this case the username and password were configured locally. By default, a self-signed certificate will be used.

Arista EOS Explorer

You will be taken to an explorer page where you can type in the CLI command and get a nice output for the body of your request. For example, if I wanted to see how to make a request body for show version, this is the output I will see from the explorer:

Arista EOS Explorer Viewer

The overview link will take you to the sample usage and background information while the command documentation will serve as reference points for the show commands. Each of the command references will contain the returned value field name, type, and a brief description. The online reference scripts from Arista uses jsonrpclib (https://github.com/joshmarshall/jsonrpclib/), which is what we will use as well. However, as of this book, it has a dependency of Python 2.6+ and not yet ported to Python 3; therefore, we will use Python 2.7 for the examples.

By the time you read this book, there might be an updated status. Please read the GitHub pull request (https://github.com/joshmarshall/jsonrpclib/issues/38) and the GitHub README (https://github.com/joshmarshall/jsonrpclib/) for the latest status.

Installation is straightforward using easy_install or pip:

$ sudo easy_install jsonrpclib
$ sudo pip install jsonrpclib
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.86.211