加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ts_dna.py 1.01 KB
一键复制 编辑 原始数据 按行查看 历史
现任明教教主-乾颐堂 提交于 2018-02-02 19:14 . 新建 ts_dna.py
import requests
import json
controller = "devnetapi.cisco.com/sandbox/apic_em"
def getTicket():
url = "https://"+controller+"/api/v1/ticket"
payload = {"username":"devnetuser","password":"Cisco123!"}
header = {'content-type': 'application/json'}
response = requests.post(url, data = json.dumps(payload), headers=header,verify=False)
print(response)
r_json = response.json()
tiket = r_json["response"]["serviceTicket"]
return tiket
def getNetworkDevices(ticket):
url = "https://" + controller + "/api/v1/network-device"
header = {"content-type":"application/json","X-Auth-Token":ticket}
response = requests.get(url, headers=header,verify=False)
print("Network Devices = ")
print(json.dumps(response.json(),indent=4,separators=(',',': ')))
r_json = response.json()
for i in r_json["response"]:
print(i["id"] + " " + '{:53}'.format(i["series"]) + " " + i["reachabilityStatus"])
theTicket=getTicket()
getNetworkDevices(theTicket)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化