实验7:基于REST API的SDN北向应用实践

基本要求,OpenDaylight的北向接口




delete.py

import requests as rq
from requests.auth import HTTPBasicAuth

if __name__ == '__main__':
    url = 'http://127.0.0.1:8181/restconf/operational/opendaylight-inventory:nodes/node/openflow:1/'
    headers = {'Content-Type': 'application/json'}
    response = rq.delete(url=url, headers=headers, auth=HTTPBasicAuth('admin', 'admin'))
    print(response.content)

time.py

import requests
from requests.auth import HTTPBasicAuth

if name == "main":
url = 'http://127.0.0.1:8181/restconf/config/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/flow/1'
with open("./timeout.json") as f:
jstr = f.read()
headers = {'Content-Type': 'application/json'}
res = requests.put(url, jstr, headers=headers, auth=HTTPBasicAuth('admin', 'admin'))
print (res.content)

get.py

import requests as rq
from requests.auth import HTTPBasicAuth
def http_get(url):
    url= url
    headers = {'Content-Type':'application/json'}
    resp = rq.get(url,headers=headers,auth=HTTPBasicAuth('admin','admin'))
    return resp

if __name__ == "__main__":
    url='http://127.0.0.1:8181/restconf/operational/opendaylight-inventory:nodes/node/openflow:1/flow-node-inventory:table/0/opendaylight-flow-table-statistics:flow-table-statistics'
    resp = http_get(url)
    print(resp.content)


### RYU
![](https://img2022.cnblogs.com/blog/2844949/202210/2844949-20221030195842153-61310144.png)
![](https://img2022.cnblogs.com/blog/2844949/202210/2844949-20221030195848876-2126402847.png)
posted @ 2022-10-30 19:59  3133348311  阅读(10)  评论(0编辑  收藏  举报