netbox-community / go-netbox

The official Go API client for Netbox IPAM and DCIM service.
Other
194 stars 144 forks source link

Remove description from ip address #84

Closed smutel closed 4 years ago

smutel commented 4 years ago

Hello,

I created an IP address with go-netbox with the parameters below:

When I want to update the description, it's working fine:

params := &models.WritableIPAddress{}

address := "192.168.56.1/24"
params.Address = &address

description := "Description updated"
params.Description = description

resource := ipam.NewIpamIPAddressesUpdateParams().WithData(params)
_, err = client.Ipam.IpamIPAddressesUpdate(resource, nil)
if err != nil {
  return err
}

Here is what I see throw tcpdump:

{"address":"192.168.56.1/24","created":"0001-01-01","description":"Description updated","last_updated":"0001-01-01T00:00:00.000Z","nat_outside":null,"tags":[]}

But if I would like to remove the description from that IP address, it does not work. I use the same code than above but I don't set description. Here is what I see throw tcpdump:

{"address":"192.168.56.1/24","created":"0001-01-01","last_updated":"0001-01-01T00:00:00.000Z","nat_outside":null,"tags":[]}

If I check in Netbox, the description is still there.

Also what is the difference between PartialUpdate and Update functions ?

Thanks.

fbreckle commented 4 years ago

Hi,

not really affiliated with the devs of go-netbox, but here are my observations from writing my own netbox provider:

I found that for comments on virtual machines, updating with a single space string (" ") works to delete the string.

As to what is the difference between Partial und normal update: My assumption is that per https://netbox.readthedocs.io/en/stable/api/overview/#what-is-a-rest-api , partial update should probably be PATCH whereas normal update is PUT. If I remember correctly, tests on this are not really reflecting this, though. You might want to try it againg yourself.

smutel commented 4 years ago

Oh. Thanks. What is the link of your provider ?

fbreckle commented 4 years ago

Its not public yet, since its heavy WIP. I invited you.

smutel commented 4 years ago

Here is mine if you want to look at it: https://github.com/smutel/terraform-provider-netbox

smutel commented 4 years ago

Perhaps we can try to move all this work to netbox-community to share the effort ?

I tried you option with description and it is working as expected. I did the same thing for DNS name and unfortunately it is not working :cry:

fbreckle commented 4 years ago

The error is probably the same as https://github.com/netbox-community/go-netbox/issues/54