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