WAPI: update host record, create if it does not exist
Hi all,
I need a solution to place DNS record via WAPI.
Create is working with:
curl -k \
-u 'user:pass' \
-H 'Content-Type: application/json' \
-X POST 'https://my.ipam.com/wapi/v2.13.6/record:host' \
-d '{"ipv4addrs": [
{
"ipv4addr": "10.10.10.1"
}
],
"name": "devicename.my.network.com"}'
also updating is working with:
curl -k \
-u 'user:pass' \
-H 'Content-Type: application/json' \
-X POST 'https://my.ipam.com/wapi/v2.13.6/request' \
-d '[
{
"method": "STATE:ASSIGN",
"data": {
"host_name": "devicename.my.network.com"
}
},
{
"method": "GET",
"object": "record:host",
"data": {
"name": "##STATE:host_name:##"
},
"assign_state": {
"host_ref": "_ref"
},
"enable_substitution": true,
"discard": true
},
{
"method": "PUT",
"object": "##STATE:host_ref:##",
"enable_substitution": true,
"data": {
"ipv4addrs": [
{
"ipv4addr": "10.10.10.99"
}
]
},
"args": {
"_return_fields": "ipv4addrs"
},
"assign_state": {
"updated_ip": "ipv4addrs"
},
"discard": true
},
{
"method": "STATE:DISPLAY"
}
]'
my idea was to try updating and if it does not exist, to create the record. code for this idea:
curl -k \
-u 'user:pass' \
-H 'Content-Type: application/json' \
-X POST 'https://my.ipam.com/wapi/v2.13.6/request' \
-d '[
{
"method": "STATE:ASSIGN",
"data": {
"host_name": "devicename.my.network.com"
}
},
{
"method": "GET",
"object": "record:host",
"data": {
"name": "##STATE:host_name:##"
},
"assign_state": {
"host_ref": "_ref" //<-- Here I am getting already an error, if the object does not exist
},
"enable_substitution": true,
"discard": true
},
{
"method": "IF",
"condition": "##STATE:host_ref:##",
"then": [
{
"method": "PUT",
"object": "##STATE:host_ref:##",
"enable_substitution": true,
"data": {
"ipv4addrs": [
{
"ipv4addr": "192.168.1.100"
}
]
},
"args": {
"_return_fields": "ipv4addrs"
},
"assign_state": {
"updated_ip": "ipv4addrs"
},
"discard": true
}
],
"else": [
{
"method": "POST",
"object": "record:host",
"data": {
"name": "##STATE:host_name:##",
"ipv4addrs": [
{
"ipv4addr": "192.168.1.100"
}
]
},
"assign_state": {
"new_host_ref": "_ref"
},
"discard": true
}
]
},
{
"method": "STATE:DISPLAY"
}
]'
the error I am getting is:
{ "Error": "AdmConProtoError: The operation returned an empty list ([]) assign_state is supported only when the result operation returns a single result.",
"code": "Client.Ibap.Proto",
"text": "The operation returned an empty list ([]) assign_state is supported only when the result operation returns a single result."
} ✓
any idea how to update records in a easy way? why update doesn't create the object if it does not exist? would be much easier 😅
Comments
-
Hi all,
I need a solution to place DNS record via WAPI.
Yeah, totally get what you mean 😅 it would be nice if the
update()method automatically created the object when it doesn’t exist! But by design, most frameworks (like Django ORM or SQLAlchemy) separate update and create to avoid accidental data changes.0 -
yeah, I see - but if this is stsrictly separated, why there is no easy CREATE & UPDATE api - doesn't make sense for my understanding 😂
0 -
dear infloblox…. I really do not understand the API.
figure this out please:
my Hostname is Uppercase - e.g.
MYHOST(fqdn would be MYHOST.network.dns.zone).Creating the entry results in:
myhost.network.dns.zone←this is always LOWERCASE (!)the update via API is doing a String-Compare which is CASE SENSITIVE - REALLY????
works as designed?
0 -
I think the RESTful API meets its goals and follows RFCs for the FQDN per the WAPI admin guide; I would approach this a different way, in that I'd use a python script that would handle the Update error and then call a function to create the new host record.
0 -
i wish I could!
but the device is a hardened wifi-bridge, which is not allowing scripts or similar. The only allowed is a ipsec post hook which is allowing me to call a API.
I am heading to do the automatically creation on my ticketing sytem for every rolled out device. the wifi-bridge itself will allways just update the record.
thanks for sharing your ideas and trying to help guys!
0 -
What is the shell that you are using to execute the curl command? Could you create a bash function, for example, that would perform a similar approach to what I suggested with the Python script?
0 -
This has nothing to do with the API and is just following the DNS standard. DNS is lowercase, so all FQDN entries will be converted to lowercase, regardless of your case preference.
0
Categories
- All Categories
- 5.2K Forums
- 4.7K Critical Network Services
- 472 Security
- Visibility and Insights
- Ideas Portal
- Webinars & Events
- 279 Resources
- 279 News & Announcements
- Knowledge Base
- Infoblox Documentation Portal
- Infoblox Blog
- Support Portal
- 10 Members Hub
- 4 Getting Started with Community
- 6 Community Support

