Closes #20399: Add assigned and primary filters for MACAddress #1031

Closed
opened 2026-04-05 19:56:27 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @pheus on 10/19/2025

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!

*Originally created by @pheus on 10/19/2025* <!-- 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!
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#1031