-
Notifications
You must be signed in to change notification settings - Fork 1
/
cellreq.py
51 lines (42 loc) · 1.67 KB
/
cellreq.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import requests
import json
from requests.packages.urllib3.exceptions import InsecureRequestWarning
from requests import Session
from requests.exceptions import HTTPError
class enmRestSession(Session):
"""
Inherit requests.Session object for connecting
and authenticating on ENM for REST NBI service
(ALEX: Configuration Tasks - CM Cell
Management REST Northbound Interface).
Raises HTTPError if it can't login in.
"""
def __init__(self, enm, login, password):
super().__init__()
self.enm = enm if enm[-1] == "/" else f"{enm}/"
self.headers.update({"Content-Type": "application/json"})
self.verify = False
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
login_str = f"{enm}login?IDToken1={login}&IDToken2={password}"
rest_response = self.post(login_str)
if rest_response.status_code != requests.codes.ok:
raise HTTPError()
def send_configuration_task(self, request_body):
url = f"{self.enm}configuration-tasks/v1/tasks"
resp = self.post(url, data=json.dumps(request_body))
return resp
def __exit__(self, exc_type, exc_val, exc_tb):
try:
self.get(f"{self.enm}logout")
finally:
super().__exit__(self, exc_type, exc_val, exc_tb)
def main():
param = {"name": "readCells", "fdn": "NetworkElement=RNC01"}
with enmRestSession(
"https://iegtbl8030-7.gtoss.eng.ericsson.se/",
"login",
"pass"
) as s:
print(s.send_configuration_task(param).json()["requestResult"])
if __name__ == "__main__":
main()