Thursday, August 20, 2015

Network Device API intro "Postman"

Playing around with the basics on network device API calls again.  Postman is a great tool to try things out interactively.  Works great for me as a Chrome plugin.




Kudos to Matt Oswalt for a great post on Nexus 9000 NX-API


Finally, a little bit of super generic Python for getting 'show version' from a switch:

import requests
import json

url='http://YOURIP/ins'
switchuser='USERID'
switchpassword='PASSWORD'

myheaders={'content-type':'application/json-rpc'}
payload=[
          {
                  "jsonrpc": "2.0",
                  "method": "cli",
                  "params": {
                             "cmd": "show version",
                                    "version": 1
                            },
                   "id": 1
           }
          ]
response = requests.post(url,data=json.dumps(payload), headers=myheaders,auth=(switchuser,switchpassword)).json()


No comments:

Post a Comment