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

(andrew) #1
with manager.connect(
host=NXOS_HOST,
port=NETCONF_PORT,
username=USERNAME,
password=PASSWORD,
hostkey_verify=False
) as device:
# Add loopback interface
print("\n Adding Loopback {} with IP
address {} to device {}...\n".\
format(LOOPBACK_ID, LOOPBACK_IP,
NXOS_HOST))
netconf_response =
device.edit_config(target='running',
config=add_loop_interface)
# Print the XML response
print(netconf_response)
if __name__ == '__main__':
add_loopback()

After importing the manager module from the ncclient
library, the connection details for the NETCONF server
are specified. The loopback interface ID and IP address
that will be created are also defined at this point in the
script. The add_loopback() function contains the XML
document that specifies the NETCONF configuration
information in the add_loop_interface variable. The
YANG model that is used in this case is specified through
the XPath value,
xmlns=“http://cisco.com/ns/yang/cisco-nx-os-
device”. Recall that this YANG data model is included
by default in Cisco NX-OS. The actual path in the treelike
YANG model where the configuration changes are going
to be performed is also included in the XML document.
This XML document matches one to one the YANG data
model cisco-nx-os-device. The script uses the
connect method next to establish a connection to the
NETCONF server and then send the XML configuration
document to the running data store. The response
received is displayed to the console using the print

Free download pdf