Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a filter for device.primary_ip4 and primary_ip6 to the REST API / graphQL #11150

Closed
michaelarnauts opened this issue Dec 9, 2022 · 3 comments · Fixed by #11382
Closed
Assignees
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application

Comments

@michaelarnauts
Copy link
Contributor

NetBox version

v3.3.9

Feature type

Change to existing functionality

Proposed functionality

I would like to be able to fetch a device based on it's primary ipv4 (and probably also ipv6). I understand IP addresses aren't unique (you can them in multiple VRF's), but it should still be posible to get the device based on the ID of the IP Address.

Related to #10058

Mentioned here https://groups.google.com/g/netbox-discuss/c/Di5VMTtK5lg

Use case

I'm pushing devices to netbox trough a script with the API, and it happens that a device already exists with the same primary IP address. I want to handle these cases (probably by removing the old device).

When adding the device, I currently only get the error Device with this Primary IPv4 already exists, but there is no way to find this actual device.

I assign the IP address to an interface of the new device before I can configure the primary IP, but somehow while doing this, the IP address is still linked to an old device, causing that device to have a primary IP4 that isn't linked to any of its interfaces.

Once this happens, it's not possible anymore to find the actual device to remove it.

Database changes

No response

External dependencies

No response

@michaelarnauts michaelarnauts added the type: feature Introduction of new functionality to the application label Dec 9, 2022
@dsobon
Copy link

dsobon commented Dec 9, 2022

I've had to do this in my bulk import python code, when a device gets renamed from the source:

fix_nb_device = [nb_device for nb_device in nb_devices if str(nb_device) == nb_address.assigned_object.device.name]
fix_nb_device[0].update({ 'primary_ip4': None })
nb_address.assigned_object_type = None
nb_address.assigned_object_id = None
nb_address.save()

This presumes nb_devices contains all netbox device objects, and nb_address is the "Primary IPv4 already exists" netbox address object.

However, I also do a cleanup of devices in netbox that do not exist any more in the source... (if done in the start, rather than at the end, then the above logic is not required)

@jeremystretch jeremystretch added the status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation label Dec 13, 2022
@michaelarnauts
Copy link
Contributor Author

@jeremystretch i'm willing to take a look add adding this filter, doesn't seem that hard.

@kkthxbye-code kkthxbye-code added status: accepted This issue has been accepted for implementation and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels Jan 4, 2023
@kkthxbye-code
Copy link
Contributor

@michaelarnauts - All yours :)

michaelarnauts added a commit to michaelarnauts/netbox that referenced this issue Jan 4, 2023
jeremystretch added a commit that referenced this issue Jan 5, 2023
* Closes #11150: Add a filter for device.primary_ip4 and primary_ip6

* Tweaked tests to query for multiple IDs

Co-authored-by: jeremystretch <jstretch@ns1.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants