Reply
Highlighted
Accepted Solution

Deleting All PTR records Matching Search

Authority
Posts: 24
3676     0

With an A or Host record it's easy to delete all records in a zone. However, for PTR records they are just dumped into a global 10.in-addr.arpa reverse zone so just deleting or emptying the zone is not an option.

 

I have a search query that works perfectly:

https://[gridmaster]/wapi/v2.3.1/recordSmiley Tonguetr?_return_type=json-pretty&view=default&ptrdname~=.if.network.example.com

 

There will be about 3000 PTR records that match this record. 

 

I have two questions:

  1. Querying via a browser HTTP request like the above will limit to 1000 records. Is this limit imposed when running API calls using the python requests module? (Can I increase that limit with the _max_results option?)
  2. Is the best methodology for deleting all of these records to simply iterate through the returned data and run a delete API call for each record? Or is there a way to simply tell the API to delete everything matching the search?

Any examples would be extremely helpful. 

Re: Deleting All PTR records Matching Search

[ Edited ]
Moderator BRampling
Moderator
Posts: 69
3677     0

 

1) Yes, use _max_results

 

2) Here's a script that deletes all the ptrs in a specified domain suffix (using the ~= search option on ptrdname):

 

#!/usr/bin/python

import sys,requests

from requests.auth import HTTPBasicAuth

 

ptrdname = sys.argv[1]

urlstub = 'https://10.60.27.4/wapi/v2.6/'

 

payload = {'ptrdname~': ptrdname}

resp = requests.get(urlstub + 'recordSmiley Tonguetr', auth=HTTPBasicAuth('admin', 'infoblox'),verify=False,params=payload)

#print resp

j = resp.json()

for k in j:

        print k['_ref']

        url = urlstub + k['_ref']

        print url

        resp = requests.delete(url, auth=HTTPBasicAuth('admin', 'infoblox'),verify=False)

Re: Deleting All PTR records Matching Search

Moderator BRampling
Moderator
Posts: 69
3677     0

Even better, here's a script that creates 3000 PTR records in the requested zone and network. Usage:

 

./createptrs.py if.network.example.com 9.0.0.0/8

 

 

 

#!/usr/bin/python
import sys,requests,json
from requests.auth import HTTPBasicAuth

domsuf = sys.argv[1]
network = sys.argv[2]
urlstub = 'https://10.60.27.4/wapi/v2.6/'
count = 3000
x = 1 

while x <= count:
        ptrdname = 'test' + str(x) + '.' + domsuf
        url = urlstub + 'record:ptr'
        payload = '{"ptrdname":"' + ptrdname + '","ipv4addr":"func:nextavailableip:' + network + '"}'
        print url 
        print payload
        try:
                resp = requests.post(url, auth=HTTPBasicAuth('admin', 'infoblox'),verify=False,data=payload)
                resp.raise_for_status()
                print resp
        except requests.exceptions.HTTPError as e:  # This is the correct syntax                print e
        x += 1 

 

 

Re: Deleting All PTR records Matching Search

[ Edited ]
Moderator BRampling
Moderator
Posts: 69
3677     0

 

And here's a script to delete them all again from the specified domain suffix. It does iterate through the list so it's not very fast. Unfortunately PTRs cannot be removed via CSV import since that is usually the fastest method. Note the maxresults variable is 3100 here, change it as you see fit. Usage:

 

./deleteptrs.py .if.network.example.com
#!/usr/bin/python
import sys,requests
from requests.auth import HTTPBasicAuth

ptrdname = sys.argv[1]
urlstub = 'https://10.60.27.4/wapi/v2.6/'
maxresults = str(3100)

payload = '{"ptrdname~":"' + ptrdname + '"}'
url = urlstub + 'record:ptr?_max_results=' + maxresults

try:
        resp = requests.get(url, auth=HTTPBasicAuth('admin', 'infoblox'),verify=False,data=payload)
        resp.raise_for_status()
        print resp
except requests.exceptions.HTTPError as e:
        print resp.content
        print e
j = resp.json()
for k in j:
        url = urlstub + k['_ref']
        try:
                resp = requests.delete(url, auth=HTTPBasicAuth('admin', 'infoblox'),verify=False)
                resp.raise_for_status()
                print resp
        except requests.exceptions.HTTPError as e:
                print resp.content
                print e

 

 

 

Re: Deleting All PTR records Matching Search

Authority
Posts: 24
3677     0

Okay so it really is just as simple as iterating through based on a search, and then sending a delete. That works. I don't necessarily care how fast or slow this runs as it only has to run about once a month anyway. I could probably use multiprocessing but I don't want to overload the Infoblox servers, either. 

 

Thank you!

Re: Deleting All PTR records Matching Search

KD
Techie
Posts: 1
3677     0

Hi All, 

 

I am new for infoblox. Got a task I have few server list with IP address which I need to be deleted. Can i get it via csv import? If yes please send me format of header.

Re: Deleting All PTR records Matching Search

Adviser
Posts: 75
3677     0

Hi,

 

While doing the CSV Import, you need to select the DELETE option(as shown in the image attached)

 

This is the sample CSV file you can use.

header-ptrrecord,address,dname*
PtrRecord,172.26.1.100,a.demo.com
PtrRecord,172.26.1.101,b.demo.com

Hope this works for you,

Krishna

Showing results for 
Search instead for 
Do you mean 

Recommended for You