DevNet Associate DEVASC 200-901 Official Certification Guide by Adrian Iliesiu (z-lib.org)

(andrew) #1
#!/usr/bin/env python
""" Get the capabilities of a remote device
with NETCONF """
from ncclient import manager
NXOS_HOST = "10.10.10.10"
NETCONF_PORT = "830"
USERNAME = "admin"
PASSWORD = "password"
# create a get_capabilities() method
def get_capabilities():
"""
Method that prints NETCONF capabilities of
remote device.
"""
with manager.connect(
host=NXOS_HOST,
port=NETCONF_PORT,
username=USERNAME,
password=PASSWORD,
hostkey_verify=False
) as device:
# print all NETCONF capabilities
print('\n***NETCONF Capabilities for
device {}***\n'.format(NXOS_HOST))
for capability in
device.server_capabilities:
print(capability)
if __name__ == '__main__':
get_capabilities()

After importing the manager module from ncclient, the
NETCONF server IP address, port number, username,
and password are defined. The get_capabilities()
function establishes a connection to the NETCONF
server, retrieves the server capabilities with
device.server_capabilities(), iterates with a for loop
over each capability, and displays the capabilities to the
console. Example 12-13 shows the result of running this
script on a Cisco Nexus 9000 switch running Cisco NX-
OS 9.2.3 with NETCONF enabled.

Free download pdf