Posted on April 17, 2019 12:30 am
 |  Asked by Nilesh Bhadane
 |  529 views
1
0
Print Friendly, PDF & Email

Hi,

Is there a way to write a python or Java program or script to login to Arista device & perform an action on the arista device?

Thanks,
Nilesh

1
Posted by Himanshu Singh
Answered on April 17, 2019 6:25 am

Hi Nilesh,

You can use Arista eAPI to configure the switch via JSON-RPC.

For more information about eAPI please refer to the following:
https://eos.arista.com/arista-eapi-101/

For more information on Python Client for eAPI (pyeapi):
https://eos.arista.com/introducing-the-python-client-for-eapi-pyeapi/
https://eos.arista.com/working-with-the-python-eapi-client/
https://pyeapi.readthedocs.io/en/latest/

Documentation on Arista’s integration with Ansible:
https://eos.arista.com/arista-ansible-getting-started/

HTH
Himanshu

1
Posted by Pratik
Answered on April 17, 2019 9:58 am

You can use python client for this.

1) First install python client (pyeapi)
2) This python client requires a configuration file, so create one config file and mention the device details in
it. For example,
$ cat .eapi.conf
[connection: DEVICE NAME]
host: MANAGEMENT IP
username: XXXXXX
password: XXXXXX
transport: http
You can also put multiple nodes (devices) in config file.
3) Run python
4) Import pyeapi
5) Connect to node first, with below command,
node = pyeapi.connect_to(‘DEVICE NAME’)
6) from pprint import pprint as pp…….to print output
7) Now you can execute show commands in python,
pp (node.enable(‘show version’))
pp (node.enable([‘show version’, ‘show ip route’]))……if you want to execute multip command together
8) Also you can execute config commands,
node.config([‘interface ethernet 4/1’ , ‘description Test_1’])

1
Posted by Gerard Phillips
Answered on April 17, 2019 11:41 am

Hi Nilesh,

Absolutely. You can use python or Java, and the appropriate libraries to remotely access an Arista switch for both configuration and monitoring purposes.

There is a great article here that outlines the steps you need to take and points at a bunch more resources:
https://eos.arista.com/arista-eapi-101/

There are loads of examples that you can use, or build on here:
https://github.com/arista-eosext

Cheers
Gerard

1
Posted by Adam Levin
Answered on April 17, 2019 2:10 pm

Hello Nilesh. The feature you are looking for is called eAPI, our EOS Application Programming Interface. It uses JSON, and the JSONRPC Library is supported in most any programming or scripting language. Our Arista Programming Essentials class teaches Python, so we usually recommend that.

You can enable eAPI on a switch by entering the commands

Switch#conf
Switch(config)#username Script secret Arista
Switch(config)#management api http-commands
Switch(config-mgmt-api-http-cmds)#no shutdown

You will also need to create a user, but you can use existing users from AAA configuration,local or TACACS, etc.

Once enabled you can go to the URL of the management interface on the switch:

https:///explorer.html

You can navigate, explore, and read the documentation from this link. Note that anything you do in the tool will actually run and be executed on the switch so be careful.

Post your Answer

You must be logged in to post an answer.