blob: 7488af9a55793e10e1b25fd10b7c43fb9448d35c [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):
Shad Ansariec6bbd32021-12-10 20:57:16 +000031 print("Set {} mbr to {}".format(device_group, mbr))
Shad Ansari5e8d0692021-12-08 19:09:34 +000032 m = {'uplink' : mbr}
Shad Ansari3a48b642021-12-01 22:42:19 +000033 url = URL + "vcs/vcs/vcs-{}/slice/mbr".format(device_group)
Shad Ansari5e8d0692021-12-08 19:09:34 +000034 response = requests.post(url, headers=headers(key), json=m)
Shad Ansari3a48b642021-12-01 22:42:19 +000035 assert response.status_code == 201, "Failed to set mbr"
Shad Ansari2ecc6522021-12-03 21:03:48 +000036 if response.status_code != 201:
37 print("Failed to set mbr, device_group:{}, mbr:{}, status_code: {}".format(device_group, mbr, response.status_code))
Shad Ansari3a48b642021-12-01 22:42:19 +000038
Shad Ansari3a48b642021-12-01 22:42:19 +000039if __name__ == '__main__':
Shad Ansari5e8d0692021-12-08 19:09:34 +000040 key = ""
41 cameras = "menlo-4g-cameras"
42 #cameras = "cameras-4g"
43
44 mbr = get_mbr(key, cameras)
Shad Ansari3a48b642021-12-01 22:42:19 +000045 print("uplink mbr:{}, downlink mbr: {}".format(mbr["uplink"], mbr["downlink"]))
Shad Ansari5e8d0692021-12-08 19:09:34 +000046 set_mbr(key, cameras, 5000000)
47 mbr = get_mbr(key, cameras)
Shad Ansariab4141c2021-12-03 03:33:18 +000048 print("uplink mbr:{}, downlink mbr: {}".format(mbr["uplink"], mbr["downlink"]))
Shad Ansari5e8d0692021-12-08 19:09:34 +000049 set_mbr(key, cameras, 10000000)
50 mbr = get_mbr(key, cameras)
Shad Ansari3a48b642021-12-01 22:42:19 +000051 print("uplink mbr:{}, downlink mbr: {}".format(mbr["uplink"], mbr["downlink"]))