Shad Ansari | 3a48b64 | 2021-12-01 22:42:19 +0000 | [diff] [blame^] | 1 | """ |
| 2 | SPDX-FileCopyrightText: 2020-present Open Networking Foundation <info@opennetworking.org> |
| 3 | SPDX-License-Identifier: LicenseRef-ONF-Member-1.01 |
| 4 | """ |
| 5 | |
| 6 | import requests |
| 7 | import json |
| 8 | from requests.structures import CaseInsensitiveDict |
| 9 | |
| 10 | TOKEN = '### A VALID TOKEN ###' |
| 11 | |
| 12 | #URL = "https://roc.aetherproject.org/aether-roc-api/aether/v4.0.0/connectivity-service-v4/" |
| 13 | URL = "https://roc.staging.aether.onlab.us/aether-roc-api/aether/v4.0.0/connectivity-service-v4/" |
| 14 | |
| 15 | roc_headers = CaseInsensitiveDict() |
| 16 | roc_headers["Content-Type"] = "application/json" |
| 17 | roc_headers["Authorization"] = "Bearer " + TOKEN |
| 18 | |
| 19 | |
| 20 | def get_mbr(device_group): |
| 21 | url = URL + "vcs/vcs/vcs-{}/slice/mbr".format(device_group) |
| 22 | response = requests.get(url, headers=roc_headers) |
| 23 | assert response.status_code == 200, "Failed to get mbr" |
| 24 | mbr = json.loads(response.text) |
| 25 | return mbr |
| 26 | |
| 27 | |
| 28 | def set_mbr(device_group, mbr): |
| 29 | url = URL + "vcs/vcs/vcs-{}/slice/mbr".format(device_group) |
| 30 | response = requests.post(url, headers=roc_headers, json=mbr) |
| 31 | assert response.status_code == 201, "Failed to set mbr" |
| 32 | |
| 33 | |
| 34 | if __name__ == '__main__': |
| 35 | mbr = get_mbr("cameras-4g") |
| 36 | print("uplink mbr:{}, downlink mbr: {}".format(mbr["uplink"], mbr["downlink"])) |
| 37 | mbr={'downlink':mbr["downlink"],'uplink':mbr["uplink"]} |
| 38 | set_mbr("cameras-4g", mbr) |
| 39 | mbr = get_mbr("cameras-4g") |
| 40 | print("uplink mbr:{}, downlink mbr: {}".format(mbr["uplink"], mbr["downlink"])) |