dnaeon / pyinfoblox

Infoblox WAPI module for Python
16 stars 11 forks source link

Fixes params vs data issues, adds support for objref form to get method. #5

Closed philipsd6 closed 9 years ago

philipsd6 commented 9 years ago

POST calls that include functions must be in data, not params, but parameters such as _return_fields must be in params, not data. So this splits the kwargs into params and data, based on the fact that all params have a leading underscore.

As shown using requests directly:

# This works, and we get the objref returned:
data = {'ipv4addr':'func:nextavailableip:192.168.10.0/24',
         'match_client':'RESERVED'}
r = session.post('https://infoblox/wapi/v1.4/fixedaddress', data=json.dumps(data))
print(r.content)

# But adding _return_fields causes it to fail:
data.update({'_return_fields':'ipv4addr'})
r = session.post('https://infoblox/wapi/v1.4/fixedaddress', data=json.dumps(data))
print(r.content)

# And switching to `params` doesn't work either, due to the func:nextavailableip call:
r = session.post('https://infoblox/wapi/v1.4/fixedaddress', params=data)
print(r.content)

Also, support was added to the get method for direct objref style, which returns a single object instead of a objtype list:

>>> infoblox.fixedaddress.get(objref)
{u'_ref': u'fixedaddress/ZG5zLmZpeGVkX2FkZHJlc3MkMTkyLjE2OC4xMC4xMC4wLi4:192.168.1.10/default',
 u'ipv4addr': u'192.168.1.10',
 u'network_view': u'default'}
philipsd6 commented 9 years ago

For reference: Can't use nextavailableip function AND _return_fields in WAPI POST calls; many thanks to Frank Hecker for the assistance.

dnaeon commented 9 years ago

Merged, thanks Philip! :)