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