Reply

Entering multiple A records for same IP

ku0100
Techie
Posts: 7
3096     0

I'm messing around with the Python Infoblox API and having difficulty getting a records with the same IP address but different domain names to push to the database.

 

For instance:

 

1.1.1.1 test.com

1.1.1.1 test2.com

 

currently, only the first entry will be entered into the database. Is there any way to force Infoblox to add another A record instead of just updating or ignoring if it sees a matching IP already exists?

 

Thank you

 

Re: Entering multiple A records for same IP

Moderator BRampling
Moderator
Posts: 69
3097     0

Could you post an example of your script?

Re: Entering multiple A records for same IP

[ Edited ]
ku0100
Techie
Posts: 7
3097     0

Sure, pasted below.

 

from netaddr import *
import logging
import certifi
import urllib3
import time
import requests
import json
import getpass
import sys
import os
import fnmatch
import re
import validators
import infoblox_client # Is this redundant with below?
from infoblox_client import connector
from infoblox_client import objects

# These are for the infoblox lab test environment
infoblox_IP = 'x.x.x.x' 
infoblox_username = 'username'
infoblox_password = 'password'
infoblox_zone = 'any_domain'
opts = {'host': infoblox_IP, 'username': infoblox_username, 'password': infoblox_password}
conn = connector.Connector(opts)
wapi_url = 'https://infoblox-lab-url/wapi/v2.2.2/'


def aRecord():
    x = 0
    a_record_ips = []
    a_record_names = []
    print('''
        ***************************************************************************************
        **** NOTE: After entering the final record addition, just press [ENTER] to proceed ****
        ***************************************************************************************
        ''')
    while True:
        print('What is the IP address of the A record?')
        record_IP = input('> ')
        if record_IP == '':
            if len(a_record_ips) < 1:
                print('''
                    Returning to Main Menu!
                    ''')
            elif len(a_record_ips) == len(a_record_names):
                aRecordAdd(a_record_ips, a_record_names)
            else:
                # raise an error explaining not enough names were added
                aRecord()
        else:
            a_record_ips.append(record_IP)
        while True:
            print('What is the domain name of the A record?')
            record_name = input('> ') + infoblox_zone
            if record_name == '':
                continue    # Can't enter an IP without a domain name ;)
            else:
                a_record_names.append(record_name)
                break

def aRecordAdd(ips,names):
    os.system('cls')
    print('''
        Please confirm the addition of the following record(s):
        ''')
    x = 0
    while x < len(ips):
        print(str(x + 1) + '. ' + ips[x] + ' - ' + names[x])
        x += 1
    user_choice = input('> ')
    if user_choice == '':
        y = 0
        while y < len(ips):
            newRecord = objects.ARecordBase.create(conn, check_if_exits=False, ip=ips[y], name=names[y])
            y += 1
        print('''
            %s Records have been added
            ''' % (len(ips)))
    else:
        print('') 

 

Re: Entering multiple A records for same IP

[ Edited ]
ku0100
Techie
Posts: 7
3097     0

Hey @BRampling, any update on this issue?

 

Thanks

 

Re: Entering multiple A records for same IP

Moderator BRampling
Moderator
Posts: 69
3097     0

I can reproduce your issue but don't see a way around it. Could you open an issue in:

 

https://github.com/infobloxopen/infoblox-client

 

And I will try to get someone to follow up on it.

Re: Entering multiple A records for same IP

ku0100
Techie
Posts: 7
3097     0

Ok i submitted an issue:

 

https://github.com/infobloxopen/infoblox-client/issues/171

 

thank you for your help

 

Showing results for 
Search instead for 
Do you mean 

Recommended for You