blob: a9477f1e2915af4576cee1e5055da0e68411beb9 [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 +000011URL = "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 Ansariab4141c2021-12-03 03:33:18 +000014
Shad Ansari5e8d0692021-12-08 19:09:34 +000015def headers(key):
16 h = CaseInsensitiveDict()
17 h["Content-Type"] = "application/json"
18 h["Authorization"] = "Bearer " + key
19 return h
Shad Ansari3a48b642021-12-01 22:42:19 +000020
Shad Ansari5e8d0692021-12-08 19:09:34 +000021def get_mbr(key, device_group):
Shad Ansari3a48b642021-12-01 22:42:19 +000022 url = URL + "vcs/vcs/vcs-{}/slice/mbr".format(device_group)
Shad Ansari5e8d0692021-12-08 19:09:34 +000023 response = requests.get(url, headers=headers(key))
Shad Ansari2ecc6522021-12-03 21:03:48 +000024 if response.status_code != 200:
25 print("Failed to get mbr, status_code: {}".format(response.status_code))
26 return None
Shad Ansari3a48b642021-12-01 22:42:19 +000027 mbr = json.loads(response.text)
28 return mbr
29
Shad Ansari5e8d0692021-12-08 19:09:34 +000030def set_mbr(key, device_group, mbr):
31 m = {'uplink' : mbr}
Shad Ansari3a48b642021-12-01 22:42:19 +000032 url = URL + "vcs/vcs/vcs-{}/slice/mbr".format(device_group)
Shad Ansari5e8d0692021-12-08 19:09:34 +000033 response = requests.post(url, headers=headers(key), json=m)
Shad Ansari3a48b642021-12-01 22:42:19 +000034 assert response.status_code == 201, "Failed to set mbr"
Shad Ansari2ecc6522021-12-03 21:03:48 +000035 if response.status_code != 201:
36 print("Failed to set mbr, device_group:{}, mbr:{}, status_code: {}".format(device_group, mbr, response.status_code))
Shad Ansari3a48b642021-12-01 22:42:19 +000037
Shad Ansari3a48b642021-12-01 22:42:19 +000038if __name__ == '__main__':
Shad Ansari5e8d0692021-12-08 19:09:34 +000039 key = ""
40 cameras = "menlo-4g-cameras"
41 #cameras = "cameras-4g"
42
43 mbr = get_mbr(key, cameras)
Shad Ansari3a48b642021-12-01 22:42:19 +000044 print("uplink mbr:{}, downlink mbr: {}".format(mbr["uplink"], mbr["downlink"]))
Shad Ansari5e8d0692021-12-08 19:09:34 +000045 set_mbr(key, cameras, 5000000)
46 mbr = get_mbr(key, cameras)
Shad Ansariab4141c2021-12-03 03:33:18 +000047 print("uplink mbr:{}, downlink mbr: {}".format(mbr["uplink"], mbr["downlink"]))
Shad Ansari5e8d0692021-12-08 19:09:34 +000048 set_mbr(key, cameras, 10000000)
49 mbr = get_mbr(key, cameras)
Shad Ansari3a48b642021-12-01 22:42:19 +000050 print("uplink mbr:{}, downlink mbr: {}".format(mbr["uplink"], mbr["downlink"]))