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 | |
Shad Ansari | 3a48b64 | 2021-12-01 22:42:19 +0000 | [diff] [blame] | 10 | |
Shad Ansari | ab4141c | 2021-12-03 03:33:18 +0000 | [diff] [blame^] | 11 | TOKEN = "### A VALID TOKEN ###" |
| 12 | |
| 13 | URL = "https://roc.menlo.aetherproject.org/aether-roc-api/aether/v4.0.0/connectivity-service-v4/" |
| 14 | #URL = "https://roc.staging.aether.onlab.us/aether-roc-api/aether/v4.0.0/connectivity-service-v4/" |
| 15 | |
| 16 | cameras = "menlo-4g-cameras" |
| 17 | #cameras = "cameras-4g" |
| 18 | |
| 19 | MBR_HIGH = 4000000 |
| 20 | MBR_LOW = 2000000 |
Shad Ansari | 3a48b64 | 2021-12-01 22:42:19 +0000 | [diff] [blame] | 21 | |
| 22 | roc_headers = CaseInsensitiveDict() |
| 23 | roc_headers["Content-Type"] = "application/json" |
| 24 | roc_headers["Authorization"] = "Bearer " + TOKEN |
| 25 | |
Shad Ansari | 3a48b64 | 2021-12-01 22:42:19 +0000 | [diff] [blame] | 26 | def get_mbr(device_group): |
| 27 | url = URL + "vcs/vcs/vcs-{}/slice/mbr".format(device_group) |
| 28 | response = requests.get(url, headers=roc_headers) |
| 29 | assert response.status_code == 200, "Failed to get mbr" |
| 30 | mbr = json.loads(response.text) |
| 31 | return mbr |
| 32 | |
Shad Ansari | 3a48b64 | 2021-12-01 22:42:19 +0000 | [diff] [blame] | 33 | def set_mbr(device_group, mbr): |
| 34 | url = URL + "vcs/vcs/vcs-{}/slice/mbr".format(device_group) |
| 35 | response = requests.post(url, headers=roc_headers, json=mbr) |
| 36 | assert response.status_code == 201, "Failed to set mbr" |
| 37 | |
Shad Ansari | ab4141c | 2021-12-03 03:33:18 +0000 | [diff] [blame^] | 38 | def set_uplink_mbr_high(): |
| 39 | mbr = {'uplink' : MBR_HIGH} |
| 40 | set_mbr(cameras, mbr) |
| 41 | |
| 42 | def set_uplink_mbr_low(): |
| 43 | mbr = {'uplink' : MBR_LOW} |
| 44 | set_mbr(cameras, mbr) |
Shad Ansari | 3a48b64 | 2021-12-01 22:42:19 +0000 | [diff] [blame] | 45 | |
| 46 | if __name__ == '__main__': |
Shad Ansari | ab4141c | 2021-12-03 03:33:18 +0000 | [diff] [blame^] | 47 | mbr = get_mbr(cameras) |
Shad Ansari | 3a48b64 | 2021-12-01 22:42:19 +0000 | [diff] [blame] | 48 | print("uplink mbr:{}, downlink mbr: {}".format(mbr["uplink"], mbr["downlink"])) |
Shad Ansari | ab4141c | 2021-12-03 03:33:18 +0000 | [diff] [blame^] | 49 | set_uplink_mbr_low() |
| 50 | mbr = get_mbr(cameras) |
| 51 | print("uplink mbr:{}, downlink mbr: {}".format(mbr["uplink"], mbr["downlink"])) |
| 52 | set_uplink_mbr_high() |
| 53 | mbr = get_mbr(cameras) |
Shad Ansari | 3a48b64 | 2021-12-01 22:42:19 +0000 | [diff] [blame] | 54 | print("uplink mbr:{}, downlink mbr: {}".format(mbr["uplink"], mbr["downlink"])) |