- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Infoblox wapi python help with adding a new host to dns
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-18-2020 01:03 PM - edited 03-18-2020 01:13 PM
I am trying to create a host if it does not exist and I am having trouble with the post command. Here is what I have so far:
# prompt user for credentials to infoblox if sys.stdin.isatty(): print "Enter credentials to access infoblox" username = raw_input("Username: ") password = getpass.getpass("Password: ") else: username = sys.stdin.readline().rstrip() password = sys.stdin.readline().rstrip() # creates session to infoblox session = requests.Session() session.auth = (username, password) session.verify = False url = infobloxURL # silence http warnings urllib3.disable_warnings() ipAddress = "10.1.1.0" hostName = "zocalo" # searches the internal DNS to see if host exists response = session.get(url + 'record:host?name~=^%s.mydomain.net$' % hostName) # if there is a response, response.content will contain a json object with the properties for that host hostExists = "%s.mydomain.net" % (hostName) in response.content if hostExists == True: print ("The hostname already exists in infoblox. Please select a new hostname and try again") sys.exit(1) else: print("Success! The host does not exist in infoblox") # add a host into infoblox host = { "name":"%s.mydomain.net$" % hostName, "ipv4addrs":[ { "ipv4addr":"%s" % ipAddress } ] } response = session.post(url + 'record:host', data=host ) if response.status_code == 201: print("successfully created a new host record in infoblox") else: print("failure, host not added to infoblox") print (response.status_code)
Enter credentials to access infoblox
Username: xxxxx
Password:
Success! The host does not exist in infoblox
{ "Error": "AdmConProtoError: List value expected for field: ipv4addrs",
"code": "Client.Ibap.Proto",
"text": "List value expected for field: ipv4addrs"
}
400
Solved! Go to Solution.
Re: Infoblox wapi python help with adding a new host to dns
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2020 09:57 PM
Hi,
It seems to be an issue with the way you are passing the parameters.
This is a sample pythin script I use to create host records using Python.
import requests requests.packages.urllib3.disable_warnings() # Disable SSL warnings in requests # url = "https://grid-master/wapi/v2.11/record:host?_return_as_object=1" payload = "{\"name\":\"host.info.com\",\"ipv4addrs\": [{\"ipv4addr\":\"172.26.1.20\"}]}" headers = {'content-type': "application/json"} response = requests.request("POST", url, auth=('admin', 'Infoblox'), data=payload, headers=headers, verify=False) print(response.text)
Hope this helpful,
Regards,
Krishna Vasudevan
Re: Infoblox wapi python help with adding a new host to dns
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2020 08:03 AM
Thanks I had figured out the problem but this is a good solution for anyone else who may come across this.
Re: Infoblox wapi python help with adding a new host to dns
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2020 06:30 PM
Krishna, using this same methodology, can you post an example of searching for a host record, and then deleting it?
I can't seem to get the various commands (GET/POST/DELETE) to behave, and would appreciate seeing a common methodology.
Thanks!
Re: Infoblox wapi python help with adding a new host to dns
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2020 12:11 AM
Hi,
You can take a look the Python section of the Sample Codes in this document. Let me know if you need further assistance.
Thanks,
Krishna