Infoblox’s global team of threat hunters uncovers a DNS operation with the ability to bypass traditional security measures and control the Great Firewall of China. Read about “Muddling Meerkat” and the many other threat actors discovered by Infoblox Threat Intel here.

API & Integration, DevOps,NetOps,SecOps

Reply

Cannot perform any request on extensibleattributedef using _ref

New Member
Posts: 2
6169     0

Hello,

 

I'm having an issue when trying to perform requests on extensibleattributedef , whenever I use returned _ref i get a reference not found error.

 

Example (in python, but same issue using curl):

    url_base = "https://<infoblox_url>/wapi/v2.7"
credentials = ("username", "password")

# Network example ; OK res = requests.get("%s/network?_max_results=1" % url_base, auth=credentials, verify=False).json() print json.dumps(res, indent=4) res_ref = requests.get("%s/%s" % (url_base, res[0]["_ref"]), auth=credentials, verify=False).json() print json.dumps(res_ref, indent=4) # Extensible attribute example ; KO res = requests.get("%s/extensibleattributedef?_max_results=1" % url_base, auth=credentials, verify=False).json() # this works print json.dumps(res, indent=4) res_ref = requests.get("%s/%s" % (url_base, res[0]["_ref"]), auth=credentials, verify=False).json() # but this doesn't print json.dumps(res_ref, indent=4)

 Output:

[
    {
        "_ref": "network/ZG5zLm5ldHdvcmskMTAuMjAuMTI3LjAvMjQvMA:10.20.127.0/24/default",
        "network": "10.20.127.0/24",
        "network_view": "default"
    }
]
{
    "_ref": "network/ZG5zLm5ldHdvcmskMTAuMjAuMTI3LjAvMjQvMA:10.20.127.0/24/default",
    "network": "10.20.127.0/24",
    "network_view": "default"
}
[
    {
        "default_value": null,
        "_ref": "extensibleattributedef/b25lLmV4dGVuc2libGVfYXR0cmlidXRlc19kZWYkLkJ1aWxkaW5n:Building",
        "type": "STRING",
        "name": "Building"
    }
]
{
    "text": "Reference extensibleattributedef/b25lLmV4dGVuc2libGVfYXR0cmlidXRlc19kZWYkLkJ1aWxkaW5n:Building not found",
    "code": "Client.Ibap.Data.NotFound",
    "Error": "AdmConDataNotFoundError: Reference extensibleattributedef/b25lLmV4dGVuc2libGVfYXR0cmlidXRlc19kZWYkLkJ1aWxkaW5n:Building not found"
}

Am I doing something wrong ? Performed this test for many infoblox object type, the issue only occurs on extensibleattributedef.

 

Re: Cannot perform any request on extensibleattributedef using _ref

Moderator
Moderator
Posts: 289
6169     0

You will want to update the extattrs, not the extensibleattributedef.  The extensibleattributedef is comparable to a schema definition, whereas the extattrs is the set of attrbute/value pairs for a network object.

Re: Cannot perform any request on extensibleattributedef using _ref

[ Edited ]
New Member
Posts: 2
6169     0

But what if i want to update an extattr name from API ? I don't want to update the value of the extattr for a specific network but change the extattr property globally (this is possible from UI)

 

EDIT: and still, why is the get on extensibleattributedef using _ref not working ? Is it the desired behaviour ?

Re: Cannot perform any request on extensibleattributedef using _ref

Moderator
Moderator
Posts: 289
6169     0

This will give you a list of all the EA defs, along with their _ref:

curl -k1 -u admin:infoblox -X GET 'https://10.20.30.40/wapi/v2.7/extensibleattributedef'



It returns this array in my lab grid.  Note the square brackets. It's abbreviated, the full list is pretty long.

[
  ...
   {
        "_ref": "extensibleattributedef/b25lLmV4dGVuc2libGVfYXR0cmlidXRlc19kZWYkLlZMQU4gTmFtZQ:VLAN%20Name",
        "default_value": null,
        "name": "VLAN Name",
        "type": "STRING"
    },
    {
        "_ref": "extensibleattributedef/b25lLmV4dGVuc2libGVfYXR0cmlidXRlc19kZWYkLkRhdGEgQ2VudGVy:Data%20Center",
        "default_value": null,
        "name": "Data Center",
        "type": "ENUM"
    },
    {
        "_ref": "extensibleattributedef/b25lLmV4dGVuc2libGVfYXR0cmlidXRlc19kZWYkLk5ldHdvcmsgVHlwZQ:Network%20Type",
        "default_value": null,
        "name": "Network Type",
        "type": "ENUM"
    },
 ...
 ]




If I want just the one called "Data Center" I would do one of these, they both work the same. And note "%20" means space:

curl -k1 -u admin:infoblox -X GET 'https://10.20.30.40/wapi/v2.7/extensibleattributedef?name=Data%20Center'


or

curl -k1 -u admin:infoblox -X GET 'https://10.20.30.40/wapi/v2.7/extensibleattributedef' -H "Content-Type: application/json" -d '{"name":"Data Center"}'


returns an array (note the square brackets) with one array element:

[
    {
        "_ref": "extensibleattributedef/b25lLmV4dGVuc2libGVfYXR0cmlidXRlc19kZWYkLkRhdGEgQ2VudGVy:Data%20Center",
        "default_value": null,
        "name": "Data Center",
        "type": "ENUM"
    }
]



Now you have the EA's ref.  You can retrieve it directly:

curl -k1 -u admin:infoblox -X GET 'https://10.20.30.40/wapi/v2.7/extensibleattributedef/b25lLmV4dGVuc2libGVfYXR0cmlidXRlc19kZWYkLkRhdGEgQ2VudGVy:Data%20Center'



returns the same thing, but note that it's not in an array since we asked for a specific one:

{
    "_ref": "extensibleattributedef/b25lLmV4dGVuc2libGVfYXR0cmlidXRlc19kZWYkLkRhdGEgQ2VudGVy:Data%20Center",
    "default_value": null,
    "name": "Data Center",
    "type": "ENUM"
}



Now I can try using the EA's ref URI to update the name, changing it to "Campus":

curl -k1 -u admin:infoblox -X PUT 'https://10.20.30.40/wapi/v2.7/extensibleattributedef/b25lLmV4dGVuc2libGVfYXR0cmlidXRlc19kZWYkLkRhdGEgQ2VudGVy:Data%20Center' -H "Content-Type: application/json" -d '{"name":"Campus"}'



I get this:

"extensibleattributedef/b25lLmV4dGVuc2libGVfYXR0cmlidXRlc19kZWYkLkNhbXB1cw:Campus"


which is the new _ref for the EA.



If I search for the old name again:

curl -k1 -u admin:infoblox -X GET 'https://10.20.30.40/wapi/v2.7/extensibleattributedef' -H "Content-Type: application/json" -d '{"name":"Data Center"}'

I get an empty array:

[]


but searching for it with the new name:

curl -k1 -u admin:infoblox -X GET 'https://10.20.30.40/wapi/v2.7/extensibleattributedef' -H "Content-Type: application/json" -d '{"name":"Campus"}'


gives me the updated EA:

[
    {
        "_ref": "extensibleattributedef/b25lLmV4dGVuc2libGVfYXR0cmlidXRlc19kZWYkLkNhbXB1cw:Campus",
        "default_value": null,
        "name": "Campus",
        "type": "ENUM"
    }
]

Re: Cannot perform any request on extensibleattributedef using _ref

Moderator
Moderator
Posts: 289
6169     0

Here's the python code to retrieve the ref for the EA def, and update the name:

 

#!/usr/bin/env python3

import requests
import urllib3
import sys
import json


wapi_base = "https://10.20.30.40/wapi/v2.7/"
auth = ("admin", "infoblox")
HEADERS = {'Content-type': 'application/json'}

ses = requests.session()

payload = {'name': 'Data Center'}

r = ses.get(wapi_base + 'extensibleattributedef', json=payload, auth=auth,
					headers=HEADERS, verify=False)	

response = r.json()
my_ref = response[0]["_ref"]


print (my_ref)
print ("")




payload = {'name': 'Campus'}

print (wapi_base + my_ref)
print (payload)

r = ses.put(wapi_base + my_ref, json=payload, auth=auth,
					headers=HEADERS, verify=False)	

response = r.json()
print (response)
Showing results for 
Search instead for 
Did you mean: 

Recommended for You