Reply
Highlighted
Accepted Solution

PTR Entries with A Record Creation

Authority
Posts: 24
6220     0

I'm trying to create an A record using the API. In the GUI, there's an option "create associated PTR record". Looking at the docs for A records, it doesn't seem like theres a way to automatically create a PTR record for an A record (though, oddly enough, there is an option to DELETE the associated PTR record when you delete the A record!)

 

Am I missing something? Or will I have to also create the PTR with another API call (effectively making my Python script make literally double the number of API calls)?

 

#!/usr/bin/python

import requests
import json

username = "admin"
password = "infoblox"

url = 'https://10.10.10.10/wapi/v2.3.1/'

data = { "name":"hosta.if.network.sempra.com", "ipv4addr":"111.111.111.111", "comment":"Juniper Interface Auto-Generated by API" }

requests.packages.urllib3.disable_warnings()

r = requests.post(url+'record:a', data=json.dumps(data), verify=False, auth=(username,password))

print r.status_code

print r.content

Re: PTR Entries with A Record Creation

Moderator BRampling
Moderator
Posts: 69
6221     0

When using A and PTR record combinations you do need to run two API calls (record:a and record: ptr) to create both. If you use Host records instead of A/PTR combos it simplifies the process and ensures everything is cleaned up after the record is removed later. Generally a Microsoft sync environment is the only reason to use A/PTR instead of Host records.

Re: PTR Entries with A Record Creation

Authority
Posts: 24
6221     0

Yeah I may have to do that as it doesnt seem the "&remove_associated_ptr=1" option works on delete of the A record if the A and PTR records were created with separate API calls, either. 

Re: PTR Entries with A Record Creation

Authority
Posts: 24
6221     0

This is my Python function:

def add_dns_records(username,password,name,ipv4addr):

    url = 'https://10.10.10.10/wapi/v2.3.1/'
    comment = "Juniper Interface Auto-Generated by API"

    data_a = { "name": name, "ipv4addr": str(ipv4addr), "comment": comment }
    data_ptr = { "ptrdname": name, "ipv4addr": str(ipv4addr), "comment": comment }

    s = requests.Session()
    s.auth = (username,password)
    s.verify = False

    try:
        r = s.post(url+'record:a', data=json.dumps(data_a))
        r = s.post(url+'record:ptr', data=json.dumps(data_ptr))
    except: 
        return False

    return True

I'm trying to figure out how to re-construct that to be a host record instead. I don't want any of the extra stuff (discovery etc) to be active for any of these hosts. Just A & PTR. 

 

Can somebody point me in the right direction?

Re: PTR Entries with A Record Creation

Authority
Posts: 24
6221     0

Nervermind, it ended up being a pretty easy modification to make. Thanks for the help! 

Re: PTR Entries with A Record Creation

Authority
Posts: 42
6221     0

Can you please share your modification here?

How it you combine both or you created a host instead?

 

Thanks

Nidhi

Re: PTR Entries with A Record Creation

Authority
Posts: 24
6221     0

@NSrivastava wrote:

Can you please share your modification here?

How it you combine both or you created a host instead?

 

Thanks

Nidhi


I created a host entry just as I had said I wanted to do. 

Re: PTR Entries with A Record Creation

Authority
Posts: 15
6221     0

v2.7.1 of the API and could use the Body Request to combine the A/PTR creation.  For those interesed.

 

The Json ..

 

[
{
"method": "STATE:ASSIGN",
"data": {"name": "99test.dummyinfoblox.intra","net": "10.10.10.0/24"}},
{
"method": "POST",
"object": "record:a",
"data": {"name": "##STATE:name:##","ipv4addr": "func:nextavailableip:##STATE:net:##"},
"args": {"_return_fields": "comment,ipv4addr"},
"assign_state": {"target_ref": "_ref","target_ip":"ipv4addr"},
"enable_substitution": true,"discard": true},
{
"method": "POST",
"object": "recordSmiley Tonguetr",
"enable_substitution": true,
"data": {"ptrdname": "##STATE:name:##","ipv4addr":"##STATE:target_ip:##"},
"args": {"_return_fields": "comment,ipv4addr"},
"discard": true},
{"method": "STATESmiley Very HappyISPLAY"}
]

Showing results for 
Search instead for 
Do you mean 

Recommended for You