API Examples

Reply
Highlighted

json string for custom dhcp option.

Jeroen
Techie
Posts: 5
2203     0

Hi, I am trying to figure out a way to script adding of a dhcp and dns host to Infoblox. This part works:

 curl -k1 -u admin:infoblox -H "Content-Type: application/json" -X POST  https://infoblox/wapi/v2.5/record:host -d  '{ "name":"test002.domain.net", "ipv4addrs":[{"ipv4addr":"func:nextavailableip:x.x.x.x/23","mac":"aa:bb:cc:11:22:45"}]}'

 

 But how do I add host-name to that? Our kickstart grabs it's hostname from dhcp. I have tried stuff like:

{"num" : "12" , "value": "test002.domain.net"}

or "option" : "host-name" , "value": "test003.domain.net"

or "name" : "host-name" , "value": "test002.domain.net"

 

 It probably is something that will make me go duh, but I cant seem to find it. Any direction would be appreciated

Re: json string for custom dhcp option.

Jeroen
Techie
Posts: 5
2204     0

Latest try:

curl -k1 -u admin:infoblox -H "Content-Type: application/json" -X POST  https://infoblox/wapi/v2.5/record:host -d  '{ "name":"test003.domain.net", "ipv4addrs":[{"ipv4addr":"func:nextavailableip:x.x.x.x/23","mac":"aa:bb:cc:11:22:55"}],"options" : [ { "name": "host-name", "value": "test003.domain.net" } ] }'

 

 This causes a time out. No error, no result. Probably a syntax error in my string that I do not see?

Re: json string for custom dhcp option.

GHorne Community Manager
Community Manager
Posts: 248
2204     0

the 'options' need to be attached to each address, not to the host, so you just need to re-arrange the bracketing.

 

from this:

 

 "ipv4addrs":[{
        "ipv4addr":"func:nextavailableip:x.x.x.x/23",
        "mac":"aa:bb:cc:11:22:55"
    }],
        "options" : [{
            "name": "host-name",
            "value": "test003.domain.net" } 
    ]}'

 

to this:

 

 "ipv4addrs":[{
        "ipv4addr":"func:nextavailableip:x.x.x.x/23",
        "mac":"aa:bb:cc:11:22:55"
        "options" : [{
            "name": "host-name",
            "value": "test003.domain.net" } 
        }],
    ]}'

 

Re: json string for custom dhcp option.

omrsafetyo
Techie
Posts: 6
2204     0

GHorne, this is a good answer - but I have a question about the MAC and DHCP properties.

Isn't this a bad implementation of the underlying objects?

If I go into the DNS Records, and pull up a Host record, the DHCP enabled, and MAC Address are properties of a specific IP Address within the Host record.  Yet, the REST API forces you to supply the MAC/DHCP options as a sub-property of the ipv4addrs property, not ipv4addr.

What if you wanted to add multiple IPs to the Host, and attach a specific MAC to each one, and enable DHCP?  I'm using the following currently, but it just doesn't make sense logically to me:

{
  "name": "test.mydomain.com",
  "ipv4addrs": [
  {
    "configure_for_dhcp": true,
    "mac": "00:10:aa:bb:cc:00",
    "ipv4addr": {
      "_parameters": {
        "num": 1,
        "exclude": [
          "192.168.1.0",
          "192.168.1.1"
        ]
      },
      "_object_parameters": {
        "network": "192.168.1.0/23"
      },
      "_object_function": "next_available_ip",
      "_object": "network",
      "_result_field": "ips"
    }
  }
  ]
}

 

This just doesn't make intuitive sense to me, as I expect the Mac and configure_for_dhcp to be properties of the ipv4addr, not ipv4addrs.  What am I missing?

Showing results for 
Search instead for 
Do you mean 

Recommended for You