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 filters by primary_ips to VirtualMachine, VirtualDeviceContext models #13936

Closed
miaow2 opened this issue Sep 29, 2023 · 4 comments · Fixed by #14203
Closed

Add filters by primary_ips to VirtualMachine, VirtualDeviceContext models #13936

miaow2 opened this issue Sep 29, 2023 · 4 comments · Fixed by #14203
Assignees
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application

Comments

@miaow2
Copy link
Contributor

miaow2 commented Sep 29, 2023

NetBox version

v3.6.3

Feature type

Change to existing functionality

Proposed functionality

At this moment you can't filter virtual machines and virtual device contexts by primary_ip4 and primary_ip6 fields.

Use case

At my job, we have a workaround when we need to find a virtual machine by primary IP address. Also, I've noticed that VirtualDeviceContext model does not have these filters.
It would be great to add this functionality, I can create PR with this feature.

Database changes

No

External dependencies

No

@miaow2 miaow2 added the type: feature Introduction of new functionality to the application label Sep 29, 2023
@abhi1693
Copy link
Member

On both the models you have has_primary_ip filter which will provide a list of objects on the table. Could you specify in more details what exactly you are proposing to be changed?

@miaow2
Copy link
Contributor Author

miaow2 commented Sep 29, 2023

@abhi1693 I want to add the same functionality as on DeviceFilterSet, https://github.com/netbox-community/netbox/blob/develop/netbox/dcim/filtersets.py#L996 primary_ip4_id and primary_ip6_id attributes

For example, I have address 1.1.1.1/24 in NetBox, with has_primary_ip filter I will get all vms with primary_ips then iterate through them and find vm with primary_ip 1.1.1.1/24.
With db id of 1.1.1.1/24 I want to filter vms like this
/api/virtualization/virtual-machines/?primary_ip4_id=xxxx

@jeremystretch
Copy link
Member

These filters were added to DeviceFilterSet under #11150 but for some reason not replicated for virtual machines.

@jeremystretch jeremystretch added the status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation label Nov 6, 2023
@miaow2
Copy link
Contributor Author

miaow2 commented Nov 6, 2023

@jeremystretch you can assign this issue to me

@jeremystretch jeremystretch 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 Nov 6, 2023
miaow2 pushed a commit to miaow2/netbox that referenced this issue Nov 7, 2023
jeremystretch added a commit that referenced this issue Nov 9, 2023
…ine and VirtualDeviceContext filtersets (#14203)

* Add primary_ip4 and primary_ip6 filters for VirtualMachine and VirtualDeviceContext filtersets (#13936)

* Add PrimaryIPFilterSet to __all__

---------

Co-authored-by: Artem I. Kotik <[email protected]>
Co-authored-by: Jeremy Stretch <[email protected]>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 8, 2024
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
3 participants