Advertisement
Guest User

ODL MAC

a guest
May 11th, 2017
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. import requests
  2.  
  3. #OpenDayLight RESTCONF API settings.
  4. odl_url = 'http://192.168.140.253:8181/restconf/operational/network-topology:network-topology'
  5. odl_username = 'admin'
  6. odl_password = 'admin'
  7.  
  8. # Fetch information from API.
  9. response = requests.get(odl_url, auth=(odl_username, odl_password))
  10.  
  11. # Find information about nodes in retrieved JSON file.
  12. for nodes in response.json()['network-topology']['topology']:
  13.  
  14.         # Walk through all node information.
  15.         node_info = nodes['node']
  16.  
  17.     # Look for MAC and IP addresses in node information.
  18.     for node in node_info:
  19.         try:
  20.             #node_id = node['host-tracker-service:addresses'][0]['node-id']
  21.             ip_address = node['host-tracker-service:addresses'][0]['ip']
  22.             mac_address = node['host-tracker-service:addresses'][0]['mac']
  23.             #print 'Found host %s with MAC address %s and IP address %s' % (node_id, mac_address, ip_address)
  24.             print 'Found host with MAC address %s and IP address %s' % (mac_address, ip_address)
  25.         except:
  26.             pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement