Skip to content
Go to file
Cannot retrieve contributors at this time
executable file 72 lines (60 sloc) 2.41 KB
#!/usr/bin/env python
from ncclient import manager
import sys
from lxml import etree
# Set the device variables
DEVICES = ['', '']
USER = 'admin'
PASS = 'admin'
PORT = 830
IP_INT = {'': {'loopback': 'lo103', 'ip': '', 'name': 'Loopback103'},
'': {'loopback': 'lo104', 'ip': '', 'name': 'Loopback104'}}
DEVICE_NAMES = {'': '(nx-osv9000-3)',
'': '(nx-osv9000-4)'}
# create a main() method
def main():
Main method that adds loopback interfaces to the leaf nodes using the OC model
add_oc_interface = """<config>
<interfaces xmlns="">
<description> Configured using OpenConfig Model </description>
for device in DEVICES:
with manager.connect(host=device, port=PORT, username=USER,
password=PASS, hostkey_verify=False,
device_params={'name': 'nexus'},
look_for_keys=False, allow_agent=False) as m:
# Add the loopback interface IP
print("\nNow adding IP address {} to interface {} on device {} {}...\n".format(IP_INT[device]['ip'],
IP_INT[device]['name'], DEVICE_NAMES[device], device))
new_intf = add_oc_interface.format(IP_INT[device]['loopback'], IP_INT[device]['ip'])
netconf_response = m.edit_config(target='running', config=new_intf)
# Parse the XML response
if __name__ == '__main__':