Reply
Accepted Solution

Trying to pull Extensible Attributes using Python for each request

andraspalfi
Techie
Posts: 2
4069     0

I have a python script that needs to pull extensible attributes for any networks that match some criteria. As of now, I can easily identify all of these networks, and pull their references:

payload={'network':CIDR}
r = requests.get('https://url/wapi/v1.0/network',auth=('user','pass'),verify=False,data=payload)
result_json=r.text
JSON_OUT=json.loads(result_json)
for j in JSON_OUT:
	_ref = j['_ref']

So my _ref variable has the refrence to the network I need. My next move, to pull extensible attributes, was to pass in this reference into the GET network and to choose the correct return type:

 

r = requests.get('https://url/wapi/v1.0/%s&_return_fields=extattrs' % _ref,auth=('user','pass'),verify=False)
print(r.text)

However, this returns the same thing I had before, a Network object. Using curl with the same URLs, I get even weirder behavior. It does return the extensible attributes of the network, however, it immediatley after returns the network object. So my r request object I am assuming is being overwritten by the network object, not the attribute, which is what I want. 

 

Thanks for any help!

Re: Trying to pull Extensible Attributes using Python for each request

Adviser
Posts: 49
4069     0

Hello Andraspalfi,

 

This approach makes 1 initial call + 1 call per network so it can take a while.

 

I recommend you to request the MISC return field in the initial call hence reducing to only 1 call

 

payload={'network':CIDR}
r = requests.get('https://url/wapi/v1.0/network?_return_fields%2B=extattrs',auth=('user','pass'),verify=False,data=payload)
result_json=r.text
JSON_OUT=json.loads(result_json)
for j in JSON_OUT:
	_ref = j['_ref']

 Regards

 

Nicolas

Check out our new Tech docs website at http://docs.infobox.com for latest documentation on Infoblox products.
Highlighted

Re: Trying to pull Extensible Attributes using Python for each request

andraspalfi
Techie
Posts: 2
4069     0

So when I try this I get the following error:

 

{u'text': u"When sending FORM arguments no URI arguments can be set (FORM arguments: {'network': ['some network ']}  URI arguments: {'_return_fields+': ['extattrs']}), please pass all the arguments as FORM arguments.", u'code': u'Client.Ibap.Proto', u'Error': u"AdmConProtoError: When sending FORM arguments no URI arguments can be set (FORM arguments: {'network': ['some network']}  URI arguments: {'_return_fields+': ['extattrs']}), please pass all the arguments as FORM arguments."}

So I tried to pass all as FORM arguemnts:

 

payload={'network':CIDR, '_return_fields+':['extattrs']}
r = requests.get('https://url/wapi/v1.0/network',auth=('usr','pwd'),verify=False,data=payload)

But I get the following error now:

 

{u'text': u"Unknown argument/field: 'extattrs'", u'code': u'Client.Ibap.Proto', u'Error': u"AdmConProtoError: Unknown argument/field: 'extattrs'"}
Showing results for 
Search instead for 
Do you mean 

Recommended for You