Closed caboteria closed 1 year ago
I am experiencing the same issue. It is unclear to me how to make a change to a single field of an existing Ip Address.
Can someone please provide some guidance?
Kind Regards,
Here is what I have so far, but let me warn you.... it's not pretty and I suspect there is a better way.
func (n *Netbox) UpdateIpAddress(ipAddress *models.IPAddress) error {
updates := IpToWriteable(ipAddress)
params := ipam.NewIpamIPAddressesPartialUpdateParams()
params.SetID(ipAddress.ID)
params.WithData(updates)
_, err := n.client.Ipam.IpamIPAddressesPartialUpdate(params, nil)
if err != nil {
return err
}
return nil
}
func IpToWriteable(ip *models.IPAddress) *models.WritableIPAddress {
status := ip.Status.Value
tags := []*models.NestedTag{}
for _, tag := range ip.Tags {
tags = append(tags, &models.NestedTag{
Name: tag.Name,
Slug: tag.Slug,
})
}
writeable := models.WritableIPAddress{
Address: ip.Address,
AssignedObject: ip.AssignedObject,
AssignedObjectID: ip.AssignedObjectID,
AssignedObjectType: ip.AssignedObjectType,
Created: ip.Created,
CustomFields: ip.CustomFields,
Description: ip.Description,
Display: ip.Display,
DNSName: ip.DNSName,
ID: ip.ID,
Tags: tags,
Status: *status,
URL: ip.URL,
}
return &writeable
}
As the library is automatically generated from the Netbox OpenAPI specification, and this issue is specification-related, it should be reported to the Netbox project.
Now, the only field of the WritableIPAddress
struct without omitempty
is Address
. Maybe there's some reason for this, but I don't know.
Hi Folks,
I'd like to change just the status of a specific IP address but am having trouble with the golang client stubs sending too many address parameters. My code looks like this:
but what goes over the wire looks like:
This causes a 400 response.
I looked at https://pkg.go.dev/github.com/netbox-community/go-netbox/netbox/models?tab=doc#WritableIPAddress and the extra fields that I'm getting in the json don't have "omitempty" in their declaration. Should I be using something different than models.WritableIPAddress so that only the parameters that I set get serialized or am I doing something tragically wrong?
Thanks!