Add filters by primary_ips to VirtualMachine, VirtualDeviceContext models #8696

Closed
opened 2025-12-29 20:40:03 +01:00 by adam · 4 comments
Owner

Originally created by @miaow2 on GitHub (Sep 29, 2023).

Originally assigned to: @miaow2 on GitHub.

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

Originally created by @miaow2 on GitHub (Sep 29, 2023). Originally assigned to: @miaow2 on GitHub. ### 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
adam added the status: acceptedtype: feature labels 2025-12-29 20:40:03 +01:00
adam closed this issue 2025-12-29 20:40:03 +01:00
Author
Owner

@abhi1693 commented on GitHub (Sep 29, 2023):

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?

@abhi1693 commented on GitHub (Sep 29, 2023): 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?
Author
Owner

@miaow2 commented on GitHub (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

@miaow2 commented on GitHub (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`
Author
Owner

@jeremystretch commented on GitHub (Nov 6, 2023):

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

@jeremystretch commented on GitHub (Nov 6, 2023): These filters were added to DeviceFilterSet under #11150 but for some reason not replicated for virtual machines.
Author
Owner

@miaow2 commented on GitHub (Nov 6, 2023):

@jeremystretch you can assign this issue to me

@miaow2 commented on GitHub (Nov 6, 2023): @jeremystretch you can assign this issue to me
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8696