THE GAME HAS CHANGED

Introducing Infoblox Universal DDI ManagementTM

Watch the launch to discover the new era of management for critical network services. Watch Now

API & Integration, DevOps,NetOps,SecOps

Reply

Help to create script to change multiple dhcp ranges member assignment at once

Posts: 13
7938     1

I have two DHCP members – both in HA.  Both DHCP members are serving different networks without any failover association configured.

 

If one DHCP member completely fails – meaning both HA nodes go down – I need to quickly assign the DHCP ranges for those networks to the other DHCP member.  I am not great in the programming area and would like some assistance in to:

  1. Needing to retrieve the grid member that has all dhcp ranges assigned to that grid member
  2. If it is one member, change it to the other member

Re: Help to create script to change multiple dhcp ranges member assignment at once

Adviser
Posts: 109
7938     1

You actually don't need any scripting or programming to accomplish this. The CSV Job Manager makes this easy to accomplish.

 

  1. Use the CSV Job Manager to export all of your networks and ranges.You can find this in the vertical toolbar on the right-hand side of the page on any screen under the Data Management tab.
  2. Remove all of the columns that you do not need (any required columns are noted with an asterisk).
  3. Update the dhcp_members and member columns. If using DHCP Failover, update the failover_association column. Save this to a new file.
  4. Using the CSV Job Manager, create a new CSV import job with the job type set to override.
  5. Browse to the updated CSV file.
  6. Optional: Set the "On error" action to "Skip to the next row and continue".
  7. Run the import.
  8. Restart services once the import is complete.

Note: If all your doing is changing the member assignment, the CSV syntax will look like the following:

 

header-dhcprange,end_address*,start_address*,failover_association,member,network_view
header-reservedrange,end_address*,start_address*,,,
dhcprange,10.60.27.175,10.60.27.160,,server.infoblox.local,default
reservedrange,23.1.1.100,23.1.1.3,,,
dhcprange,192.168.100.160,192.168.100.150,,server.infoblox.local,default
dhcprange,172.31.1.200,172.31.1.100,,server.infoblox.local,default
reservedrange,82.85.82.3,82.85.82.1,,,

 

If you only have a single Network View, that column can be ommitted. If in doubt or you have multiple Network Views, include it and specify the Network View for the networks and ranges you want to update. Navigate to Administration -> Network Views to review any existing Network Views. The Network View is selected using a dropdown menu found at the top left-hand side of your Grid Manager GUI window.

 

Good luck!

 

-Tony

Re: Help to create script to change multiple dhcp ranges member assignment at once

Posts: 13
7938     1

Sweet!  I don't use the export function all that much and had forgotten about it.  I tried this on a test dhcp range and it worked.  Thank you, that's exactly what I was looking for.

Re: Help to create script to change multiple dhcp ranges member assignment at once

New Member
Posts: 1
7938     1

Hi Tony,

 

i have 100 of network configured , but not associated with DHCP grid members . I want to associate all networks to grid members , is it possible to add grid members using csv , one by one i can do from GUI.

Re: Help to create script to change multiple dhcp ranges member assignment at once

Moderator
Moderator
Posts: 321
7938     1

Yes you do this with an "override" CSV job. The CSV file should only have the columns needed to identify which networks are being changed, and the setting being changed.

 

You will also need to change the ranges within the network, and assign them to a member or a failover association.

 

For example with a single member:

 

Header-Network,address,netmask,network_view,dhcp_members
Network,10.40.0.0,255.255.0.0,default,dhcp.example.org

 

Header-DhcpRange,network_view,member,failover_association,server_association_type,start_address,end_address
DhcpRange,default,dhcp.example.org,,MEMBER,10.40.101.1,10.40.104.254

 

Or for a failover association:

 

Header-Network,address,netmask,network_view,dhcp_members
Network,10.40.0.0,255.255.0.0,default,"dhcp1.example.org,dhcp2.example.org"

 

Header-DhcpRange,network_view,member,failover_association,server_association_type,start_address,end_address
DhcpRange,default,,dhcp1-dhcp2,FAILOVER,10.40.101.1,10.40.104.254

 

Practice on a lab appliance if you have one.  Otherwise just do one network first to make sure you're happy with the results.

Re: Help to create script to change multiple dhcp ranges member assignment at once

New Member
Posts: 1
7938     1

Is there a way to find all DHCP-ranges in single view ? Problem is I can only find DHCP-range view within a subnet. " Data Management > DHCP > Networks > Networks " is not showing all DHCP ranges.

Re: Help to create script to change multiple dhcp ranges member assignment at once

Moderator
Moderator
Posts: 321
7939     1

If you mean in a single pane in the web interface?  Unfortunately no.

 

If you mean getting a list of all ranges within a Network View, you can do a global CSV export for all ranges.  It will generate a CSV file with everything, and then you can use filters in Excel to filter by Network View.

Re: Help to create script to change multiple dhcp ranges member assignment at once

[ Edited ]
Superuser
Posts: 81
7939     1

Hello Manikastuv,

 

Going forward, please consider creating a new community post for new use-cases/questions rather than posting it under an old/different post. This would increase the chances of your question to be noticed quickly & may also attract more answers. 

 

To address your question, you have 3 options :

 

1) Like what Matt said, CSV export followed by manipulations within excel.

 

2) WebAPI - you could put in the following string to your browser & get the data needed as an XML. From there you may copy/extract to get a list of all ranges.

 

https://<GM_IP>/wapi/v2.9/range?network_view=<NETWORK_VIEW_NAME>&_return_fields=start_addr,end_addr

 

3) Use the Python Script attached below & you would get a result similar to this :

 

Output:

 

     **List of DHCP ranges under default view**

 

Range 1 : 2.2.2.5 - 2.2.2.8
Range 2 : 192.168.29.50 - 192.168.29.70

 

Code:

 

# Find the list of ranges within a specific network view

import requests
import urllib3
import json
from os import system, name

def clear():
    if name == 'nt':
        _ = system('cls')
    else:
        _ = system('clear')


urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

gm_ip = input("\n\nEnter Grid master IP :")
type(gm_ip)
gm_user = input("\nEnter user name :")
type(gm_user)
gm_password = input("\nEnter password :")
type(gm_password)

continue_check = "y"

while continue_check == 'y':
    clear()
    network_view_name = input("\nEnter the exact name of Network view to be inspected :")
    urL = 'https://' + gm_ip + '/wapi/v2.9/range?network_view=' + network_view_name + "&_return_fields=start_addr,end_addr"
    #print(urL)
    response = requests.get(urL, auth=(gm_user, gm_password), verify=False)
    mid_value = response.content
    response_native = json.loads(mid_value)
    format_output_data = json.dumps(response_native, indent=1)

    if response.status_code == 200:
        print(f"\n\n\t**List of DHCP ranges under {network_view_name} view**\n")
        string_temp = ""
        count = 1
        for line in format_output_data.splitlines():
            end_string = "end_addr"
            start_string = "start_addr"
            if end_string in line:
                after_value = line[line.index(end_string)+11:]
                string_temp += after_value
            if start_string in line:
                start_value = line[line.index(start_string)+13:]
                string_temp = start_value + "-" +string_temp
                print(f"Range {count} : {string_temp}".replace('"', ' ').replace(',',''))
                string_temp = ""
                count += 1

    else:
        print("\n\nHTTP response code : " + str(
            response.status_code) + ". Error encountered")
    continue_check = input("\n\nTo try another view type 'y'. Else anything to escape :")
    type(continue_check)

 

Please note that the WAPI version used in my solutions are both 2.9. Please adjust this if necessary. Hope this would be helpful.

 

Best regards,

 

Showing results for 
Search instead for 
Did you mean: 

Recommended for You