API & Integration

Reply
Highlighted

Add a HOST with next_available IP address from a network using a complex search ( e.g Extensible Att

Authority
Posts: 15
11301     0

We are working on migrating to Infoblox for IPAM and I am running into some difficulty with the WAPI.  Currently, we are using a large SQL database for our IP information, as well as a lot of other info.  Is it possible to access the Infoblox data via SQL or do I have to stick with the WAPI/API?  I am doing this with PHP if that makes a difference.  What I am trying to do is similar to the following: "SELECT ip FROM Infoblox WHERE site like '%something%' and status = 'Unused' and comment like '%some comment%'"

 

Basically we have A LOT of IP blocks assigned based on a geographical layout, then within the multitude of blocks available for each location, we have smaller blocks, or parts of a block, allocated to different types of service.  I tried creating a host using next_available_ip, and including the extattrs filter, but that did not work.

 

We are not using this for DHCP or DNS, we have other systems that are doing that.

 

I tried to use:

 

Add a HOST with next_available IP address from a network
using a complex search ( e.g Extensible Attributes ).

You need to pass the search criteria in the _object_parameters field
not also that '_object' changes from a reference to a type

 POST /wapi/v1.2/record:host
 Content-Type: application/json

    { "name":"wapi.test.org",
      "ipv4addrs":[
            ipv4addr" : {
                "_function" : 'next_available_ip' ,
                "_object_field" : 'value' ,
                "_object" : 'network'
                "_object_parameters" : {
                    "*Site" : "Santa Clara"
                },
                "_parameters" : {
                   "num" : 1,
                   "exclude" : [ '45.0.1.1' , '45.0.1.2' ],
                }
            }
        ]
    }

by sending 

{"name":"some host","ipv4addrs":{"ipv4addr":{"_function":"next_available_ip","_object_field":"value","_object":"network","_object_parameters":{"*Site":"the site"},"_result_field":"ips","_parameters":{"num":"1"}}}}

but I get 

Requests_Response Object
(
    [body] => { "Error": "AdmConProtoError: Result set too large (> 1000)", 
  "code": "Client.Ibap.Proto", 
  "text": "Result set too large (> 1000)"
}
    [raw] => HTTP/1.1 400 Bad Request

 

in return.

 

Any help would be greatly appreciated.

 

Thanks,

Patrick

Re: Add a HOST with next_available IP address from a network using a complex search ( e.g Extensible

Adviser
Posts: 147
11302     0

Hi Patrick,

 

There is not a SQL interface is the DB is proprietary and not directly exposed so the WAPI is what you will want to leverage.

 

From the error it appears that you are running into a max results issue which defaults to 1000. There is an option you can specify in your call to increase this. From the WAPI guide:

 

   

_max_results

Maximum number of objects to be returned. If set to a negative number the appliance will return an error when the number of returned objects would exceed the setting. The default is -1000. If this is set to a positive number, the results will be truncated when necessary.

   
   
   
   
   
   
   

 

If you add something to your call such as  &_max_results=10000 (for example) you will be able to increase the results returned.

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

Re: Add a HOST with next_available IP address from a network using a complex search ( e.g Extensible

Authority
Posts: 15
11302     0

I found the problem when I had tried _max_results.  I was doing record:host/?_max_results, when it should have been record:host?_max_results.  I was sticking a / in there.  Now I just have to get it to search using the extensible attributes.

 

Thanks,

Patrick

Re: Add a HOST with next_available IP address from a network using a complex search ( e.g Extensible

Authority
Posts: 15
11302     0

I am using this PHP code.

$data = array(
"name" => $accountnumber.".domain.com",
'ipv4addrs' => array('ipv4addr' => array(
"_function" => "next_available_ip",
"_object_field" => "value",
"_object" => "network",
"_object_parameters" =>array("*Site"=>$olt),
"_result_field" => "ips",
"_parameters" => array("num"=>$numips))));

 

It is ignoring the _object_parameters, not even looking at the site.  Also, it is pulling used IPs and not unused.  Any ideas on what I need to do to this code? I am doing a json_encode on the $data and a get to try to find the ips. 

 

get($this->uri.'record:host?_max_results='.$numips,$data,$options)

Re: Add a HOST with next_available IP address from a network using a complex search ( e.g Extensible

Authority
Posts: 15
11302     0

I forgot to say the json looks like:

{"name":"host.com","ipv4addrs":{"ipv4addr":{"_function":"next_available_ip","_object_field":"value","_object":"network","_object_parameters":{"*Site":"site"},"_result_field":"ips","_parameters":{"num":"5"}}}}

 

Re: Add a HOST with next_available IP address from a network using a complex search ( e.g Extensible

Adviser
Posts: 147
11302     0

Ensure you have an existing EA defined as "Site" and you are passing a search value for site that exists. 

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

Re: Add a HOST with next_available IP address from a network using a complex search ( e.g Extensible

Authority
Posts: 15
11302     0

I do.  I have my code sanatized.  I can pull by IP and see the site info under EA.  When I am running this query, it is returning everything.

Re: Add a HOST with next_available IP address from a network using a complex search ( e.g Extensible

Adviser
Posts: 147
11302     0

Here are a couple of things to try/check to determine why your objects seem to be ignored:

 

1. The WAPI version you are calling. The original example lists 1.2 which does not support many of the latest calls. Change your call to reference a newer version such as 2.0 if you have not already.

 

2. The object references syntax

 

For example, something like this should work:

 

{
    "name": "test.example.com",
    "ipv4addrs": [
        {
            "ipv4addr": {
                "_object_function": "next_available_ip",
                "_object": "network",
                "_object_parameters": {"*Site" : "Santa Clara"},
"_result_field": "ips", "_parameters": { "num": 1, } } } ] }

 

 

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

Re: Add a HOST with next_available IP address from a network using a complex search ( e.g Extensible

[ Edited ]
Authority
Posts: 15
11302     0

I am using v2.2 in the call.  I put a copy of the data after it has been json encoded in an earlier post.  It looks to me like everytihng is matching up, except next_available_ip is set as _function and not _object_function.  I read one place where it was supposed to be _function.  I will change that and see if it helps.

Re: Add a HOST with next_available IP address from a network using a complex search ( e.g Extensible

Adviser
Posts: 147
11302     0

There are some slight differences in the syntax from this and the json you posted earlier.

 

For example: 

"_function": "next_available_ip"
vs
"_object_function": "next_available_ip"

 See if that makes a difference in your results at all.

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

Re: Add a HOST with next_available IP address from a network using a complex search ( e.g Extensible

Authority
Posts: 15
11302     0

I made that change, and also removed

_object_field" => "value"

and this did not make any difference.

 

Re: Add a HOST with next_available IP address from a network using a complex search ( e.g Extensible

Adviser
Posts: 43
11302     0

Did you try to do a search on the network object with this EA and confirm whether or not it is returning any networks?

 

E.g. curl -k1 -u ibuser:ibuser -H "Content-Type: application/json" -X GET 'https://10.10.100.81/wapi/v2.2/network?*Site=site'

 

 

Re: Add a HOST with next_available IP address from a network using a complex search ( e.g Extensible

Authority
Posts: 15
11302     0

Yes I have.  I even built a page that allows me to perform different types of searches based on the field being searched.  It is like it ignores the EA, as well as the number of IP's requested and dumps everything back out.  Since I am setting the max results to equal the number of IPs, I am able to see what it is returning.  Also, since I am only doing 5 IPs, the ones that are being returned are all in use, and not a part of the site I am searching for.

Re: Add a HOST with next_available IP address from a network using a complex search ( e.g Extensible

Authority
Posts: 15
11302     0

I am able to use 

$this->uri.'record:host?_return_fields%2B=extattrs&*'.$ea, array(), $options

to get results for the value of EA I am using in the query.

 

Re: Add a HOST with next_available IP address from a network using a complex search ( e.g Extensible

Adviser
Posts: 43
11302     0

The uri you have above is for host records.  Is the EA you are trying to search for set on the networks or on the host records?  

Re: Add a HOST with next_available IP address from a network using a complex search ( e.g Extensible

Authority
Posts: 15
11302     0

I have actually tried it both ways, as host and as network.  We don't use the DNS function, so we are having to figure out the best way of doing this.  The Site info is set on the Network container, then as we assign an IP, we set it on the IP address as well.  The reason I am using host is because of the following example on https://community.infoblox.com/t5/API-Integration/The-definitive-list-of-REST-examples/td-p/1214.  If I need to change this to make it work, please let me know what I should use.

 

Add a HOST with next_available IP address from a network
using a complex search ( e.g Extensible Attributes ).

You need to pass the search criteria in the _object_parameters field
not also that '_object' changes from a reference to a type

 POST /wapi/v1.2/record:host
 Content-Type: application/json

    { "name":"wapi.test.org",
      "ipv4addrs":[
            ipv4addr" : {
                "_function" : 'next_available_ip' ,
                "_object_field" : 'value' ,
                "_object" : 'network'
                "_object_parameters" : {
                    "*Site" : "Santa Clara"
                },
                "_parameters" : {
                   "num" : 1,
                   "exclude" : [ '45.0.1.1' , '45.0.1.2' ],
                }
            }
        ]
    }

 

Re: Add a HOST with next_available IP address from a network using a complex search ( e.g Extensible

Authority
Posts: 15
11302     0

My end goal is to mark an IP assigned to a customer, as well as fill in some EA info.  I can do this already, but I need to be able to find the next available IP from a lot of different blocks by narrowing it down to the geographical location as well as what the particular block, or even sub-block is being used for.

Re: Add a HOST with next_available IP address from a network using a complex search ( e.g Extensible

Authority
Posts: 15
11302     0

Any update on this?  This is a very large project for us, and we have multiple other projects pending resolution of this.  By large, I am talking about over 200K IP addresses, both public and private.

Re: Add a HOST with next_available IP address from a network using a complex search ( e.g Extensible

Adviser
Posts: 43
11302     0

For the next available IP search to work, you need to have the EA set on the network(s) that you want to allocate IPs from.  Having the EA set on the container will not work unless you also have EA inheritance set on the network(s).

 

It may be better to take this offline and set up a meeting to review specifics of your environment.  You can work through your Infoblox account team to set up the meeting or else please send me a message directly and we'll work out the details.

 

Thanks,

 

John

Showing results for 
Search instead for 
Do you mean 

Recommended for You