Skip to content

Instantly share code, notes, and snippets.

@fredhsu
Created February 13, 2014 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fredhsu/8981308 to your computer and use it in GitHub Desktop.
Save fredhsu/8981308 to your computer and use it in GitHub Desktop.
Example of polling an interface for statistics in eAPI and Python
from jsonrpclib import Server
import time
username = "fredlhsu"
password = "arista"
host = "172.22.28.37"
def getInterfaceStats():
dictionary = eApiCall()
interfaces = []
response = ""
for i in range(1,5):
name = "Ethernet{}".format(i)
intf = {"name":name, "stats":dictionary["interfaces"][name]["interfaceStatistics"]}
interfaces.append(intf)
return interfaces
def eApiCall():
switch = Server( "http://{}:{}@{}/command-api".format(username, password, host))
response = switch.runCmds( 1, ["show interfaces"] )
return response[0]
if __name__ == '__main__':
sleepTime = 1
while True:
time.sleep(sleepTime)
print getInterfaceStats()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment