♥ 1 |
Hi, I am trying to do something which I thought would be fairly simple using the EOS API, alas it is causing me some issues. I want to run the command “show interfaces” via the JSON API and then extract and print various bits of information. I have started off simple by (trying) to extract the MTU. This is my Python code: import json import jsonrpclib from jsonrpclib import Server switches = ["10.2.7.170"] username = "admin" password = "admin" # Going through all the switch IP addresses listed above for switch in switches: urlString = "https://{0}:{1}@{2}/command-api".format(username, password, switch) switchReq = Server( urlString ) # Display the current interface list response = switchReq.runCmds( 1, ["show interfaces"] ) dataString = json.loads(jsonrpclib.history.response) dataDump = json.dumps(dataString,sort_keys=True,indent=2) parent = dataString["result"][0]["interfaces"] for item in parent: print item["mtu"] However when I execute I get the following error: Traceback (most recent call last):
File “getInte.py”, line 25, in <module>
print item[“mtu”]
TypeError: string indices must be integers Any suggestions on how I can correctly extract the MTU information? Here is the raw JSON output from EOS
|
Post your Answer
You must be logged in to post an answer.
If you want to quickly see all of the values for the interfaces on the switch, you can import pprint and pprint the value, try this: