[PR #20620] [MERGED] Closes #20399: Add assigned and primary filters for MACAddress #15990

Closed
opened 2025-12-30 00:25:11 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/20620
Author: @pheus
Created: 10/19/2025
Status: Merged
Merged: 10/20/2025
Merged by: @arthanson

Base: mainHead: 20399-add-additional-filtering-to-mac-addresses


📝 Commits (1)

  • 5c06fe6 feat(filtersets): Add assigned and primary filters for MACAddress

📊 Changes

5 files changed (+104 additions, -9 deletions)

View changed files

📝 netbox/dcim/filtersets.py (+34 -3)
📝 netbox/dcim/forms/filtersets.py (+20 -2)
📝 netbox/dcim/graphql/filters.py (+21 -1)
📝 netbox/dcim/tables/devices.py (+5 -2)
📝 netbox/dcim/tests/test_filtersets.py (+24 -1)

📄 Description

Fixes: #20399

This PR introduces two boolean filters on MACAddressassigned and primary — to improve filtering capabilities across the UI, REST, and GraphQL. It also adds an is_primary as a boolean column on the MAC Address table for quick visual scanning.

Summary of Changes

  • FilterSet (REST/UI):
    • Add assigned (true ⇒ MACs bound to any Interface/VMInterface; false ⇒ unassigned).
    • Add primary (true ⇒ MACs set as the primary MAC on any Interface/VMInterface; false ⇒ all others).
  • GraphQL:
    • Wire the above filters into the GraphQL filter class to maintain parity with REST/UI.
  • UI / Tables:
    • Add is_primary as a boolean column on the MAC Address table.
  • Forms:
    • Expose the new boolean filters in the MAC Address filter form.
  • Tests:
    • Unit tests for both assigned and primary filters (true/false cases).

API Examples

REST

GET /api/dcim/mac-addresses/?assigned=true
GET /api/dcim/mac-addresses/?primary=false

GraphQL

query {
  mac_address_list(filters: { assigned: true, primary: true }) {
    id
    mac_address
  }
}

Backward Compatibility

  • Additive change only; no existing behavior is altered.
  • No database migrations.

Implementation Notes

  • The table’s is_primary column is backed by a cached property to avoid repeated lookups while browsing tables.

Naming Notes

These filters are currently named assigned and primary to match existing boolean filter conventions. If the project prefers is_assigned / is_primary, I’m happy to adjust.

Happy to take any naming or scope adjustments the maintainers prefer. Thanks for the review!


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/20620 **Author:** [@pheus](https://github.com/pheus) **Created:** 10/19/2025 **Status:** ✅ Merged **Merged:** 10/20/2025 **Merged by:** [@arthanson](https://github.com/arthanson) **Base:** `main` ← **Head:** `20399-add-additional-filtering-to-mac-addresses` --- ### 📝 Commits (1) - [`5c06fe6`](https://github.com/netbox-community/netbox/commit/5c06fe6de4f5418e182ff915d9b98388a4ddefa9) feat(filtersets): Add `assigned` and `primary` filters for MACAddress ### 📊 Changes **5 files changed** (+104 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `netbox/dcim/filtersets.py` (+34 -3) 📝 `netbox/dcim/forms/filtersets.py` (+20 -2) 📝 `netbox/dcim/graphql/filters.py` (+21 -1) 📝 `netbox/dcim/tables/devices.py` (+5 -2) 📝 `netbox/dcim/tests/test_filtersets.py` (+24 -1) </details> ### 📄 Description <!-- Thank you for your interest in contributing to NetBox! Please note that our contribution policy requires that a feature request or bug report be approved and assigned prior to opening a pull request. This helps avoid waste time and effort on a proposed change that we might not be able to accept. IF YOUR PULL REQUEST DOES NOT REFERENCE AN ISSUE WHICH HAS BEEN ASSIGNED TO YOU, IT WILL BE CLOSED AUTOMATICALLY. Please specify your assigned issue number on the line below. --> ### Fixes: #20399 <!-- Please include a summary of the proposed changes below. --> This PR introduces two boolean filters on `MACAddress` — **`assigned`** and **`primary`** — to improve filtering capabilities across the UI, REST, and GraphQL. It also adds an `is_primary` as a boolean column on the MAC Address table for quick visual scanning. ### Summary of Changes - **FilterSet (REST/UI):** - Add `assigned` (true ⇒ MACs bound to any `Interface`/`VMInterface`; false ⇒ unassigned). - Add `primary` (true ⇒ MACs set as the *primary* MAC on any `Interface`/`VMInterface`; false ⇒ all others). - **GraphQL:** - Wire the above filters into the GraphQL filter class to maintain parity with REST/UI. - **UI / Tables:** - Add `is_primary` as a boolean column on the MAC Address table. - **Forms:** - Expose the new boolean filters in the MAC Address filter form. - **Tests:** - Unit tests for both `assigned` and `primary` filters (true/false cases). ### API Examples **REST** ```text GET /api/dcim/mac-addresses/?assigned=true GET /api/dcim/mac-addresses/?primary=false ``` **GraphQL** ```graphql query { mac_address_list(filters: { assigned: true, primary: true }) { id mac_address } } ``` ### Backward Compatibility - Additive change only; no existing behavior is altered. - No database migrations. ### Implementation Notes - The table’s `is_primary` column is backed by a cached property to avoid repeated lookups while browsing tables. --- ### Naming Notes These filters are currently named `assigned` and `primary` to match existing boolean filter conventions. If the project prefers `is_assigned` / `is_primary`, I’m happy to adjust. Happy to take any naming or scope adjustments the maintainers prefer. Thanks for the review! --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-30 00:25:11 +01:00
adam closed this issue 2025-12-30 00:25:11 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#15990