Skip to content

Conversation

pheus
Copy link
Contributor

@pheus pheus commented Oct 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!

Introduce Boolean filters `assigned` and `primary` to the MACAddress
filterset, improving filtering capabilities. Update forms, tables, and
GraphQL queries to incorporate the new filters. Add tests to validate
the correct functionality.

Fixes netbox-community#20399
Comment on lines +430 to +435
interface_mac_ids = models.Interface.objects.filter(primary_mac_address_id__isnull=False).values_list(
'primary_mac_address_id', flat=True
)
vminterface_mac_ids = VMInterface.objects.filter(primary_mac_address_id__isnull=False).values_list(
'primary_mac_address_id', flat=True
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review!
Quick note here: I imported VMInterface directly, while Interface is referenced via dcim.models (models.Interface). If you’d prefer consistent namespacing, I can switch to from virtualization import models as virtualization_models and use virtualization_models.VMInterface. Happy to adjust either way!

@pheus pheus marked this pull request as ready for review October 19, 2025 17:09
@jnovinger jnovinger requested review from a team and arthanson and removed request for a team October 19, 2025 17:34
Copy link
Collaborator

@arthanson arthanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @pheus !

@arthanson arthanson merged commit bbb330b into netbox-community:main Oct 20, 2025
7 checks passed
@pheus pheus deleted the 20399-add-additional-filtering-to-mac-addresses branch October 20, 2025 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add additional filtering to MAC Addresses

2 participants