Reply

Python and wapi to return host (name), ip address, and EAs for each host

[ Edited ]
Authority
Posts: 22
657     0

Complements of this forum I have a python program that returns used network percentage and various EAs.

Hello All,

I have been able to get a json object based on the script provided in "API Dummies How To Guide"

This is very helpful.  I use a similar process to get a json object based on the "record:host" object being added using the code below:

net_params = {'network_view': network_view, '_max_results': str(max_results),
'_return_fields': 'name,ipv4addrs,extattrs'}
rx = requests.get(url + 'record:host',
params=net_params,
auth=(id, pw),
verify=valid_cert)

if rx.status_code != requests.codes.ok:
print(rx.text)
exit_msg = 'Error {} finding networks: {}'
sys.exit(exit_msg.format(rx.status_code, rx.reason))

 

This gives me a json collection with all the info I need, but I am having trouble getting the "ipv4addr".

I can get the 'name' OK and the EAs, but cannot find the key to getting the ip address out of this data;.

A typical line looks like this (from the rx.json object):

[{'_ref':
'record:host_ipv4addr/ZG5zLmhvc3RfYWRkcmVzcyQuX2RlZmF1bHQubmV0LmJvZWluZ2xhYm5ldC4uMTAuNzUuMTkyLjAu:192.168.1.23/labnetwork.net/default'
, 'configure_for_dhcp': False, 'host': 'host1.labnetwork.net', 'ipv4addr': '192.68.1.23'}], 'name': 'host1'},

 

I am not seeing how to parse the json to get the data. I am using python.

 

any suggestions,

 

Thanks,

Ehol;z1

If I have posted in the wrong place, please forgive me.

Showing results for 
Search instead for 
Did you mean: 

Recommended for You