blob: ecf7e773715417309e4892b6e5c78f4092e1a297 [file] [log] [blame]
Shad Ansari3a48b642021-12-01 22:42:19 +00001"""
2SPDX-FileCopyrightText: 2020-present Open Networking Foundation <info@opennetworking.org>
3SPDX-License-Identifier: LicenseRef-ONF-Member-1.01
4"""
5
6import requests
7import json
8from requests.structures import CaseInsensitiveDict
9
Shad Ansari3a48b642021-12-01 22:42:19 +000010
Shad Ansariab4141c2021-12-03 03:33:18 +000011TOKEN = "### A VALID TOKEN ###"
12
13URL = "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
16cameras = "menlo-4g-cameras"
17#cameras = "cameras-4g"
18
19MBR_HIGH = 4000000
20MBR_LOW = 2000000
Shad Ansari3a48b642021-12-01 22:42:19 +000021
22roc_headers = CaseInsensitiveDict()
23roc_headers["Content-Type"] = "application/json"
24roc_headers["Authorization"] = "Bearer " + TOKEN
25
Shad Ansari3a48b642021-12-01 22:42:19 +000026def 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 Ansari3a48b642021-12-01 22:42:19 +000033def 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 Ansariab4141c2021-12-03 03:33:18 +000038def set_uplink_mbr_high():
39 mbr = {'uplink' : MBR_HIGH}
40 set_mbr(cameras, mbr)
41
42def set_uplink_mbr_low():
43 mbr = {'uplink' : MBR_LOW}
44 set_mbr(cameras, mbr)
Shad Ansari3a48b642021-12-01 22:42:19 +000045
46if __name__ == '__main__':
Shad Ansariab4141c2021-12-03 03:33:18 +000047 mbr = get_mbr(cameras)
Shad Ansari3a48b642021-12-01 22:42:19 +000048 print("uplink mbr:{}, downlink mbr: {}".format(mbr["uplink"], mbr["downlink"]))
Shad Ansariab4141c2021-12-03 03:33:18 +000049 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 Ansari3a48b642021-12-01 22:42:19 +000054 print("uplink mbr:{}, downlink mbr: {}".format(mbr["uplink"], mbr["downlink"]))