Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- #OpenDayLight RESTCONF API settings.
- odl_url = 'http://192.168.140.253:8181/restconf/operational/network-topology:network-topology'
- odl_username = 'admin'
- odl_password = 'admin'
- # Fetch information from API.
- response = requests.get(odl_url, auth=(odl_username, odl_password))
- # Find information about nodes in retrieved JSON file.
- for nodes in response.json()['network-topology']['topology']:
- # Walk through all node information.
- node_info = nodes['node']
- # Look for MAC and IP addresses in node information.
- for node in node_info:
- try:
- #node_id = node['host-tracker-service:addresses'][0]['node-id']
- ip_address = node['host-tracker-service:addresses'][0]['ip']
- mac_address = node['host-tracker-service:addresses'][0]['mac']
- #print 'Found host %s with MAC address %s and IP address %s' % (node_id, mac_address, ip_address)
- print 'Found host with MAC address %s and IP address %s' % (mac_address, ip_address)
- except:
- pass
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement