- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Creating DHCP range structure error
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 03:35 AM
I'm trying to create an DHCP range and adding a member that will serve the dhcp range to the clients but i keep getting a structure error. I use the python infoblox-client.
Can someone point me in the right direction?
def create_dhcp_range(api_blox, config_obj, site, name):
"""
Create a DHCP range.
Args:
api_blox (infoblox_client.connector.Connector): Infoblox API connector object.
config_obj: Configuration object with DHCP range information.
site (dict): Site information.
name (str): Name of the DHCP range.
Returns:
None
"""
subnet_key = f"{name}-ipv4_subnet"
if subnet_key not in site:
print(f"Subnet key '{subnet_key}' not found in site dictionary. Skipping DHCP range creation.")
return None
vn = config_obj.vn_list.split(',')
subnet = ipaddress.IPv4Network(site[subnet_key])
start_ip = subnet.network_address + 2
end_ip = subnet.network_address + 30
dhcp_settings = {
"start_addr": str(start_ip),
"end_addr": str(end_ip),
"name": f"{name}-{site['siteName'].split('-')[-1].strip()}",
"comment": f"{name} in {vn if name == 'AP_VLAN' else site['siteName']}",
"member": [
{'name': config_obj.member2, '_struct': 'dhcpmember'}
]
,
"server_association_type": "MEMBER",
"restart_if_needed": True
# "failover_association": "IPv4 DHCP Failover Association (ANET-Failover-Group)" (production code)
}
try:
print(dhcp_settings)
dhcp_range = objects.IPRangeV4.create(api_blox, update_if_exists=True, **dhcp_settings)
if dhcp_range:
print("DHCP range created successfully.")
except exceptions.InfobloxCannotCreateObject as e:
print(f"Failed to create DHCP range: {str(e)}")
Solved! Go to Solution.
Re: Creating DHCP range structure error
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 04:55 AM
Found the solution! The member is not a list as it is in the network creation object. So i removed that and now it works.
Re: Creating DHCP range structure error
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2023 10:05 AM - edited 07-10-2023 10:06 AM
Hi,
What WAPI version are you using?
I am trying to create/reserve a new dhcp range, with an assigned dhdp server, in IPAM, with the following parameters, but I can't see the dhcp configs shown in IPAM (ie, don't see my dhcp server assigned to the Member Assignment, for a target subnet, and no IP reservations in the Data Management's Go To DHCP View for the target subnet either).
I've been looking into the documentaiton. Are you trying to do the same thing? Does what I used (below) look right to you?
params = {
"start_addr": start_addr,
"end_addr": end_addr,
"ms_server": {"_struct": "msdhcpserver", "ipv4addr": ms_server},
"name": name,