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): |
Shad Ansari | ec6bbd3 | 2021-12-10 20:57:16 +0000 | [diff] [blame] | 31 | print("Set {} mbr to {}".format(device_group, mbr)) |
Shad Ansari | 5e8d069 | 2021-12-08 19:09:34 +0000 | [diff] [blame] | 32 | m = {'uplink' : mbr} |
Shad Ansari | 3a48b64 | 2021-12-01 22:42:19 +0000 | [diff] [blame] | 33 | url = URL + "vcs/vcs/vcs-{}/slice/mbr".format(device_group) |
Shad Ansari | 5e8d069 | 2021-12-08 19:09:34 +0000 | [diff] [blame] | 34 | response = requests.post(url, headers=headers(key), json=m) |
Shad Ansari | 3a48b64 | 2021-12-01 22:42:19 +0000 | [diff] [blame] | 35 | assert response.status_code == 201, "Failed to set mbr" |
Shad Ansari | 2ecc652 | 2021-12-03 21:03:48 +0000 | [diff] [blame] | 36 | if response.status_code != 201: |
| 37 | 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] | 38 | |
Shad Ansari | 3a48b64 | 2021-12-01 22:42:19 +0000 | [diff] [blame] | 39 | if __name__ == '__main__': |
Shad Ansari | 5e8d069 | 2021-12-08 19:09:34 +0000 | [diff] [blame] | 40 | key = "" |
| 41 | cameras = "menlo-4g-cameras" |
| 42 | #cameras = "cameras-4g" |
| 43 | |
| 44 | mbr = get_mbr(key, cameras) |
Shad Ansari | 3a48b64 | 2021-12-01 22:42:19 +0000 | [diff] [blame] | 45 | print("uplink mbr:{}, downlink mbr: {}".format(mbr["uplink"], mbr["downlink"])) |
Shad Ansari | 5e8d069 | 2021-12-08 19:09:34 +0000 | [diff] [blame] | 46 | set_mbr(key, cameras, 5000000) |
| 47 | mbr = get_mbr(key, cameras) |
Shad Ansari | ab4141c | 2021-12-03 03:33:18 +0000 | [diff] [blame] | 48 | print("uplink mbr:{}, downlink mbr: {}".format(mbr["uplink"], mbr["downlink"])) |
Shad Ansari | 5e8d069 | 2021-12-08 19:09:34 +0000 | [diff] [blame] | 49 | set_mbr(key, cameras, 10000000) |
| 50 | mbr = get_mbr(key, cameras) |
Shad Ansari | 3a48b64 | 2021-12-01 22:42:19 +0000 | [diff] [blame] | 51 | print("uplink mbr:{}, downlink mbr: {}".format(mbr["uplink"], mbr["downlink"])) |