Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #
  2. # Get running config from an IOS-XR device and print out some
  3. # interface information. Shows how to use the jxmlease library
  4. # for when you'd rather have JSON but have to deal with XML!
  5. #
  6. from ncclient import manager
  7. import jxmlease
  8.  
  9. HOST = '127.0.0.1'
  10. PORT = 8303
  11. USER = 'cisco'
  12. PASS = 'cisco'
  13.  
  14. def my_unknown_host_cb(host, fingerprint):
  15. return True
  16.  
  17. m = manager.connect(host=HOST, port=PORT, username=USER, password=PASS,
  18. timeout=600,
  19. allow_agent=False,
  20. look_for_keys=False,
  21. hostkey_verify=False,
  22. unknown_host_cb=my_unknown_host_cb)
  23.  
  24. c = m.get_config(source='running')
  25. r = jxmlease.parse(c.data_xml)
  26.  
  27. for intf in r[u'data'][u'interface-configurations'][u'interface-configuration']:
  28. if 'ipv4-network' in intf.keys():
  29. print("{} has IPv4 address {}".format(
  30. intf[u'interface-name'],
  31. intf[u'ipv4-network'][u'addresses'][u'primary'][u'address']))
  32. else:
  33. print("{} has no IPv4 network config".format(intf[u'interface-name']))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement