-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcsr-get-capabilities.py
75 lines (63 loc) · 2.86 KB
/
csr-get-capabilities.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import sys
import subprocess
from ncclient import manager
if len(sys.argv) < 2:
print("Error - Incorrect arguments")
print('Usage: python3 csr-get-capabilities.py <container_name>')
print('Example: python3 csr-get-capabilities.py clab-telemetry-testbed-r1')
exit(1)
else:
container_name = sys.argv[1]
check_container = subprocess.getoutput("docker ps -a | awk '{print $NF}' | grep " + container_name)
if check_container != container_name:
print("Error - Incorrect arguments: You need to specify the container name of the network device.")
print('Usage: python3 csr-get-capabilities.py <container_name>')
print('Example: python3 csr-get-capabilities.py clab-telemetry-testbed-r1')
exit(1)
r = {
"host": container_name,
"port": 830,
"username": "admin",
"password": "admin",
"hostkey_verify": False,
"device_params": {"name": "csr"}
}
session = manager.connect(**r)
print ("\nSession ID: ", session.session_id)
# Extract the NETCONF capabilities
capabilities = session.server_capabilities
yang_module_number = 0
netconf_extra_capability_number = 0
"""
# Get the NETCONF capabilities in raw format
for item in session.server_capabilities:
print(item)
"""
"""
Retrieve the set of YANG modules supported by the network device. For each YANG module we obtain the name,
the revision/version, and the namespace URI. In addition, certain YANG modules include additional
implementation details, such as additional features and deviations.
"""
print("\n- YANG modules supported by the network device "+ container_name + ": \n")
for capability_key in capabilities:
capability = capabilities[capability_key]
if "module" in capability.parameters:
yang_module_number = yang_module_number + 1
capability.parameters['namespace_uri'] = capability.namespace_uri
print("YANG module" + " " + str(yang_module_number) + ": " + str(capability.parameters))
print("")
"""
Retrieve the set of NETCONF server extra capabilities supported by the network device, such as XPath filtering
support in RPC operations (e.g., `urn:ietf:params:netconf:capability:xpath:1.0`) and the capability to
send notifications to subscribers (e.g., `urn:ietf:params:netconf:capability:notification:1.0`).
Each NETCONF server capability is identified by its particular namespace URI.
"""
print("\n- NETCONF server extra capabilities supported by the network device "+ container_name + ": \n")
for capability_key in capabilities:
capability = capabilities[capability_key]
if not "module" in capability.parameters:
if capability.namespace_uri:
netconf_extra_capability_number = netconf_extra_capability_number + 1
print("NETCONF extra capability" + " " + str(netconf_extra_capability_number) + ": " + str(capability.namespace_uri.replace("\n", "").replace(" ","")))
print("")
session.close_session()