Reply
Highlighted

Are there any python API available for creating DHCP scope ?

Authority
Posts: 18
5653     0

Hi Experts,

 

I am looking to write a python script to create a new DHCP scope. Are there any API available ?

 

I looked here :

 

https://github.com/infobloxopen/infoblox-client

 

but there are no support NIOS objects to achieve that.

 

Any help would be appreciated!!!

 

Thanks

Anirudh

 

 

Re: Are there any python API available for creating DHCP scope ?

BBell
Techie
Posts: 5
5654     0

I assume you mean "DHCP Range" (that is what Infoblox calls a pool of IP addresses you can have a DHCP enabled member send).

 

If you want to use Python, it would be easiest to use the Web API, information about which can be found in the "WAPI Documentation" link on your Grid GUI, or by looking at the various examples scattered around this forum.

Re: Are there any python API available for creating DHCP scope ?

Authority
Posts: 18
5654     0

Thanks for your response BBell. I found this from the forum:

 

https://community.infoblox.com/t5/Security/How-to-assign-a-router-IP-to-a-DHCP-range-using-REST/m-p/...

 

{
"member": {
"_struct": "dhcpmember",
"ipv4addr": "x.x.x.x",
"name": "infoblox.localdomain"
},
"start_addr": "x.x.x.x",
"end_addr": "x.x.x.x",
"server_association_type": "MEMBER",
"enable_ddns": true,
"use_enable_ddns": true,
"options": [
{
"name": "dhcp-lease-time",
"use_option": true,
"value": "6000",
"vendor_class": "DHCP"
},
{
"name": "routers",
"use_option": true,
"value": "x.x.x.x",
"vendor_class": "DHCP"
},
{
"name": "domain-name",
"use_option": true,
"value": "ictest.local",
"vendor_class": "DHCP"
},
{
"name": "ntp-servers",
"value": "x.x.x.x",
"vendor_class": "DHCP"
}
],
"use_options": true
}

 

Now there are few more DHCP options that i want to add like "DNS Servers" and then Custom DHCP options like DNS search path, boot file name, boot server hostname etc etc. Can you please give an example of that ?

 

Thanks in Advance!!!

Re: Are there any python API available for creating DHCP scope ?

Authority
Posts: 18
5654     0

I only found the options were very limited.

 

https://it-ipam.corp.nutanix.com/wapidoc/additional/structs.html#dhcpoption-dhcp-option

 

These options are:

  • routers
  • router-templates
  • domain-name-servers
  • domain-name
  • broadcast-address
  • broadcast-address-offset
  • dhcp-lease-time
  • dhcp6.name-servers

Where is the list of other options ?

Re: Are there any python API available for creating DHCP scope ?

Adviser
Posts: 63
5654     0

Those are only special options that are displayed separately from other options. You can simply create a new option using its code (num field) and value.

 

Re: Are there any python API available for creating DHCP scope ?

Authority
Posts: 18
5654     0

"_struct": "dhcpmember"

 

 

Why is there a _ infront of a struct ?  I am trying to get a understanding of this WEB API and any help would be appreciated.

Re: Are there any python API available for creating DHCP scope ?

Authority
Posts: 18
5654     0

{
"name": "test",
"network": "192.168.5.0/24",
"network_view": "xyz",
"start_addr": "192.168.5.154",
"end_addr": "192.168.5.254",
"server_association_type": "MS_SERVER",
"ms_server": { "_struct": "msdhcpserver",
"ipv4addr":"infoblox.localdomain"
}
}

 

 

Is this right ? Can i create a DHCP Range with the above json file with a POST ?

Re: Are there any python API available for creating DHCP scope ?

GHorne Community Manager
Community Manager
Posts: 248
5654     0

The member part of the config can be of a variable type (microsoft, grid, etc) so you need a way to define the type of object you are attaching to the network. So you add a '_struct' field to define the type. (Fields that start with an '_' are just internal fields and not directly related to the object.)

 

"ms_server": { 
        "_struct": "msdhcpserver",
        "ipv4addr":"infoblox.localdomain"
        }

"member": {
           "_struct": "dhcpmember",
           "ipv4addr" : "192.168.1.3"
        }

 

Of course some of the structures are identical, and some the type is implied when you are also declaring things like '"server_association_type": "MS_SERVER", or "ms_server":{}, but it is just an artifact of the WAPI, and you need to work with it.

 

 

Re: Are there any python API available for creating DHCP scope ?

Authority
Posts: 18
5654     0

So i ran this in my python interpreter like this :

 

Here is the differencei am seeing. If my data is just name, network, start_addr and end_addr it works just fine. But the moment i add server_association_type and ms_server dict, i get error code 400. Can someone please help ?

 

data = {
"name": "test",
"network": "192.168.10.0/24",
"network_view": "xyz",
"start_addr": "192.168.10.154",
"end_addr": "192.168.10.254",
"server_association_type": "MS_SERVER",
"ms_server": { "_struct": "msdhcpserver",
"ipv4addr":"192.168.1.3"
}
}

 

>>> import requests
>>> session = requests.Session()
>>> session.verify = False
>>> url = 'https://infoblox.localdomain/wapi/v2.3/'

>>>r = session.post(url + 'network', data=data)

>>>r.status_code
400

Re: Are there any python API available for creating DHCP scope ?

Authority
Posts: 18
5654     0

Hi Guys,

 

Figured what the problem was. I had to do json.dumps(data) in my code.

 

But now i am running into a different problem. I was to add some custom DHCP options like :

 

DNS Search Path 119

Bootfile name num 67

Boot server hostname 66

 

Can some one show me an example of how to add these above 3 options ?

 

Showing results for 
Search instead for 
Do you mean 

Recommended for You