Reply
Highlighted

API functionality for doing automated zone transfers (aka, import zone)

[ Edited ]
hp550c
Techie
Posts: 5
1408     0

Hi,

  We currently have dozens of authoritative reverse zones already created in our grid (we're getting ready to migrate things over -- we're not using the appliances in production yet).  However, I'd like to do a zone transfer from the current DNS master servers (not Infoblox) to the grid to ensure things are fresh.  From the GUI, clicking "Import Zone" for each reverse zone is an exercise in futility -- it'd take forever with the number of zones we have.  Is it possible to do an API call via curl that tells the grid to import a specific reverse zone from a specific IP?  The grid would then do an AXFR from that IP and update the records accordingly (exactly like 'Import Zone' does from the GUI)?

 

  I tried using this command:

 

curl -k -n -H "Content-Type: application/json" -X POST https://GRID/wapi/v2.3/zone_auth -d '{"fqdn":"0.10.in-addr.arpa","ns_group":"Test Group","restart_if_needed":false,"import_from":"10.11.12.13","zone_format":"IPV4"}

 

  That works, and it does the AXFR as expected, but only if the zone doesn't already exist in the grid.  If it exists, I get a "Duplicate object' error.

 

  Using the 'Import Zone' GUI method on the existing zone works fine -- it doesn't complain and happily does the AXFR without issue.  How can I make the API call do the same if the zone exists?

 

Thanks!

Re: API functionality for doing automated zone transfers (aka, import zone)

Moderator BRampling
Moderator
Posts: 69
1409     0

Have you tried using a PUT instead of a POST? PUT is used to modify existing objects. 

Re: API functionality for doing automated zone transfers (aka, import zone)

[ Edited ]
hp550c
Techie
Posts: 5
1409     0

Thanks so much, BRampling!  That was it!  For others that are looking how to do this, this is how I did it (in bash for quick and simple):

 

# Get the reference to the FQDN
curl -k -u admin:password -s -o /tmp/curl -X GET "https://GRIDIP/wapi/v2.3/zone_auth?fqdn=FQDN&view=VIEW"
 
# Grab the reference from the result
REF=`grep "_ref" /tmp/curl | awk '{print $2}' | perl -pi -e 's/\"(.*)\",/$1/g'`
 
# Submit the request to import the zone
curl -k -u admin:password -H "Content-Type: application/json" -X PUT "https://GRIDIP/wapi/v2.3/${REF}" -d '{"import_from":"MASTERIP"}'

 

Change GRIDIP, FQDN, VIEW, and MASTERIP accordingly.

 

Thanks again!

Showing results for 
Search instead for 
Do you mean 

Recommended for You