infobloxopen / infoblox-client

Infoblox NIOS Python WAPI Client
Apache License 2.0
143 stars 103 forks source link

Update if exist does no longer work after 0.5.0 #265

Closed JonasKs closed 4 years ago

JonasKs commented 4 years ago

Hi,

Update if exists no longer work in version 0.5.0.

from infoblox_client.objects import NetworkV4
NetworkV4.create(conneciton=connection, cidr='192.168.0.0/24', comment='Jonas test network', update_if_exists=True)

Results in an exception:

infoblox_client.exceptions.InfobloxCannotCreateObject: Cannot create 'network' object(s): b'{ "Error": "AdmConDataError: None (IBDataConflictError: IB.Data.Conflict:The network 192.168.0.0/24 already exists.  Select another network.)", \n  "code": "Client.Ibap.Data.Conflict", \n  "text": "The network 10.82.28.96/28 already exists.  Select another network."\n}' [code 400]

Downgrading to 0.4.25 works. I'm not able to look into this today, and I assume this is a core-thing with how you've generated your code compared to before.

Tagging @AvRajath since it's his PR.

AvRajath commented 4 years ago

@JonasKs As this was an auto generated client from the NIOS schema. There was no testing done on this. Hence this might have got missed. Will surely look into this.

JonasKs commented 4 years ago

Any status?

AvRajath commented 4 years ago

Had been occupied with other prioritized tasks. Will look into it ASAP.

AvRajath commented 4 years ago

@JonasKs It does a get object request to see if the object already exists and in this case when we do a Get the appended search fields were _search_for_update_fields = ['comment', 'network_view', 'network'] in 0.5.0 and hence the get request was making queries in this form:

GET /wapi/v2.7/network?comment=test+network&network=192.168.11.0%2F24

Wherein the comment would have to be updated but unfortunately even that goes into the search parameter. Hence we get a NONE response and the hence update fails. Removing the "comment" from _search_update_fields works fine on my local setup. But im not sure for how many objects i have to do that? May be i shall try a better method to implement this Update_if_exists. Will raise a PR Today/Tomorrow with a fix.

JonasKs commented 4 years ago

I haven't really used the 0.5.0 much(because of this), nor looked closely at the code, so I'm not sure what's the best solution to be honest. _search_update_fields sounds like the correct thing to fix, if that's it's use.

AvRajath commented 4 years ago

Fixed in #267 and seems to be working fine. Please reopen if you feel the issue hasn't been resolved

oren0e commented 2 years ago

@AvRajath Hi, I'm getting something similar with version 0.5.0. I try to update a host with a new IP so I do:

new_ip = objects.IP.create(ip="10.10.0.11", mac="88:88:88:88:88:55")  # the ip and mac here are new
objects.HostRecord.create(conn, name="host2.test_zone.local", view="default", ip=new_ip, update_if_exists=True)  # the name of the host is the existing host I want to update

I receive the error:

InfobloxCannotCreateObject: Cannot create 'record:host' object(s): b'{ "Error": "AdmConDataError: None (IBDataConflictError: IB.Data.Conflict:The record \'host2.test_zone.local\' already exists.)", \n  "code": "Client.Ibap.Data.Conflict", \n  "text": "The record \'host2.test_zone.local\' already exists."\n}' [code 400]

Is this a real error or am I using it in the wrong way?