-
Notifications
You must be signed in to change notification settings - Fork 4
/
jsonrpc_fetch.py
executable file
·44 lines (38 loc) · 1.13 KB
/
jsonrpc_fetch.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
#!/usr/bin/env python3
import requests
import json
device_list = [
"clab-dc1-pods-cr1",
"clab-dc1-pods-cr2",
"clab-dc1-pods-cr3",
"clab-dc1-pods-pod1-sp1",
"clab-dc1-pods-pod1-sp2",
"clab-dc1-pods-pod1-sp3",
"clab-dc1-pods-pod1-lf1",
"clab-dc1-pods-pod1-lf2",
"clab-dc1-pods-pod1-lf3",
"clab-dc1-pods-pod1-lf4",
"clab-dc1-pods-pod1-lf5",
"clab-dc1-pods-pod1-lf6",
]
jsonrpc_path = "/jsonrpc"
default_cred = ("admin", "NokiaSrl1!")
headers = {"Content-type": "application/json"}
def build_rpc_request(path: str, datastore: str) -> str:
body = {
"jsonrpc": "2.0",
"id": 0,
"method": "get",
"params": {"commands": [{"path": path, "datastore": datastore}]},
}
return body
for device in device_list:
url = f"https://{device}{jsonrpc_path}"
version_req = requests.post(
url,
data=json.dumps(build_rpc_request("/system/information/version", "state")),
headers=headers,
auth=requests.auth.HTTPBasicAuth(*default_cred),
verify="clab-dc1-pods/.tls/ca/ca.pem",
)
print(f"{device}: {version_req.json()['result'][0]}")