Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- # Get running config from an IOS-XR device and print out some
- # interface information. Shows how to use the jxmlease library
- # for when you'd rather have JSON but have to deal with XML!
- #
- from ncclient import manager
- import jxmlease
- HOST = '127.0.0.1'
- PORT = 8303
- USER = 'cisco'
- PASS = 'cisco'
- def my_unknown_host_cb(host, fingerprint):
- return True
- m = manager.connect(host=HOST, port=PORT, username=USER, password=PASS,
- timeout=600,
- allow_agent=False,
- look_for_keys=False,
- hostkey_verify=False,
- unknown_host_cb=my_unknown_host_cb)
- c = m.get_config(source='running')
- r = jxmlease.parse(c.data_xml)
- for intf in r[u'data'][u'interface-configurations'][u'interface-configuration']:
- if 'ipv4-network' in intf.keys():
- print("{} has IPv4 address {}".format(
- intf[u'interface-name'],
- intf[u'ipv4-network'][u'addresses'][u'primary'][u'address']))
- else:
- print("{} has no IPv4 network config".format(intf[u'interface-name']))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement