Arista EOS

For this blog I’m using a Arista vEOS 4.15.2.1F and
Ubuntu 16.04 Linux with Python. Please see
references section below for more details of vEOS. Also please see the second blog article (part2) for details of how to install the requests module.

Arista Setup

On the Arista switch then all we have to do is the following
from the configuration prompt

management api http-commands

no shut

username eosapi privilege 15 role
network-admin secret eosapi

Now we can open a web browser to the switch and get a feel
for the API. For example my vEOS VM is
using IP 192.168.229.61:

Next let’s open an interactive Python session and create a
REST connection to the Arista switch. In
the first instance we’ll just run a show command. The “s” object is the session to the Arista
switch and the “r” object is the response data.

We can now do some checks against the session and response
data, please see the previous blog posts for details. However assuming that is all correct, we’ll just dive right into looking at the response data
payload:

print json.dumps(r.json(),
indent=2)

{

"jsonrpc": "2.0",

"result": [

{

"hostname": "vEOS1",

"fqdn": "vEOS1"

}

],

"id": "PythonScript-1"

}

Example 1

For the next example I’ll just make a small change to the
previous JSON payload to run two different show commands and run the REST call
again. With the Arista API then we just
pass a list object with our commands so it is very easy to add or pop items as
needed:

data['params']['cmds'] = ['show
hostname','show interfaces status']

r = s.request('post', uri,
data=json.dumps(data))

print json.dumps(r.json(),
indent=2)

{

"jsonrpc": "2.0",

"result": [

{

"hostname": "vEOS1",

"fqdn": "vEOS1"

},

{

"interfaceStatuses": {

"Management1": {

"description":
"",

"duplex":
"duplexFull",

"vlanInformation": {

"interfaceMode":
"routed",

"interfaceForwardingModel": "routed"

},

"bandwidth": 1000000000,

"interfaceType":
"10/100/1000",

"autoNegotiateActive":
true,

"autoNegotigateActive":
true,

"linkStatus":
"connected",

"lineProtocolStatus":
"up"

}

}

}

],

"id": "PythonScript-1"

}

Example 2

For the next example we’ll add a new loopback interface to demonstrate
using configuration commands:

Like NX-API then the Arista REST API is very easy to use as
long as you know what commands you want to run on the cli.

One thing to note is that you must pass the exact command. For example ‘show interface status’ will not work
in the API, even though it works on the CLI (as the CLI auto completes the interface
keyword, adding the s on the end). However
‘show interfaces status’ will work OK.