https://www.cupfighter.net/2014/01/configure-arista-eapi-with-python http://ylb.jp/EOSdev/eAPI/eAPItest.html ================================================================================================== management api http-commands no shutdown username eapi secret 0 password management api http-commands protocol https no shut show management api http-commands https://gist.github.com/fredhsu/8970833#file-eapi-example-vlans-py ================================================================================================== eAPI-example-vlans.py ------------------------ #!/usr/bin/env python import json from jsonrpclib import Server switches = ["172.22.28.156", "172.22.28.157", "172.22.28.158"] username = "admin" password = "admin" # Going through all the switch IP addresses listed above for switch in switches: urlString = "https://{}:{}@{}/command-api".format(username, password, switch) switchReq = Server( urlString ) # Display the current vlan list response = switchReq.runCmds( 1, ["show vlan"] ) print "Switch : " + switch + " VLANs: " print response[0]["vlans"].keys() # Add vlan 100 to the switch print "Adding vlan 100" response = switchReq.runCmds( 1, ["enable", "configure", "vlan 100"] ) # List the vlans again to show vlan 100 configured response = switchReq.runCmds( 1, ["show vlan"] ) print "Switch : " + switch + " VLANs: " print response[0]["vlans"].keys() print print "\n*** Done adding vlan to switches ***\n" # Go through them again to remove the vlan for switch in switches: urlString = "https://{}:{}@{}/command-api".format(username, password, switch) switchReq = Server( urlString ) # Remove vlan 100 print switch + " : removing vlan 100" response = switchReq.runCmds( 1, ["enable", "configure", "no vlan 100", "end"] ) print response print "\n*** Script done ***" http://packetpushers.net/arista-eapi/ ================================================================================================== import jsonrpclib from pprint import pprint ip = '10.10.10.10' port = 8543 # port is mapped from 443 to 8543 in my environment username = 'eapi' password = 'password' eapi_url = 'https://{}:{}@{}:{}/command-api'.format(username, password, ip, port) exec-show-version.py --------------------- # Execute 'show version' on the remote switch using eAPI response = eapi_conn.runCmds(1, ['show version']) pprint(response) [{u'architecture': u'i386', u'bootupTimestamp': 1238983442.141455, u'hardwareRevision': u'', u'internalBuildId': u'57cbbdaf-f64d-4492-87eb-6cd4fc157125', u'internalVersion': u'4.12.1-1356975.vEOS4123', u'memFree': 264596, u'memTotal': 1001284, u'modelName': u'vEOS', u'serialNumber': u'', u'systemMacAddress': u'52:54:00:01:37:37', u'version': u'4.12.1-1356975.vEOS4123 (engineering build)'}] ================================================================================================== Remove-vlan-10.py ----------------- #!/usr/bin/env python import json from jsonrpclib import Server #switches = ["172.22.28.156", "172.22.28.157", "172.22.28.158"] switches = ["172.16.43.158"] username = "klink" password = "klink" # Going through all the switch IP addresses listed above for switch in switches: urlString = "https://{}:{}@{}/command-api".format(username, password, switch) switchReq = Server( urlString ) # Display the current vlan list response = switchReq.runCmds( 1, ["show vlan"] ) print "Switch : " + switch + " VLANs: " print response[0]["vlans"].keys() # Add vlan 100 to the switch print "Adding vlan 100" response = switchReq.runCmds( 1, ["enable", "configure", "vlan 100"] ) # List the vlans again to show vlan 100 configured response = switchReq.runCmds( 1, ["show vlan"] ) print "Switch : " + switch + " VLANs: " print response[0]["vlans"].keys() print print "\n*** Done adding vlan to switches ***\n" # Go through them again to remove the vlan for switch in switches: urlString = "https://{}:{}@{}/command-api".format(username, password, switch) switchReq = Server( urlString ) # Remove vlan 10 print switch + " : removing vlan 10" response = switchReq.runCmds( 1, ["enable", "configure", "no vlan 10", "end"] ) print response print "\n*** Script done ***" ================================================================================================== ================================================================================================== ================================================================================================== ================================================================================================== ================================================================================================== ================================================================================================== ================================================================================================== ================================================================================================== ================================================================================================== ==================================================================================================