[PR #20851] [MERGED] Closes #20564: Many-to-many pass-through port mappings #16069

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

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/20851
Author: @jeremystretch
Created: 11/20/2025
Status: Merged
Merged: 12/9/2025
Merged by: @arthanson

Base: featureHead: 20564-port-mappings


📝 Commits (10+)

  • 0901694 Initial work on FR #20788 (cable profiles)
  • a20ac40 Add missing filters for cable_position
  • 481811e Misc cleanup
  • 7edea73 Add initial cable path tests for profiles
  • fe95d89 Fix test
  • 2fe5323 Add topology tests for cable profiles
  • fb2ea37 Simplify A/B side popping logic
  • 24c6653 Add profile for 4x4 MPO8 shuffle cable
  • a75dee7 Enable drag-and-drop of items within multiselect fields
  • aa7eeda Remove many-to-one profiles

📊 Changes

35 files changed (+2501 additions, -930 deletions)

View changed files

📝 netbox/dcim/api/serializers_/base.py (+52 -0)
📝 netbox/dcim/api/serializers_/device_components.py (+43 -18)
📝 netbox/dcim/api/serializers_/devicetype_components.py (+45 -8)
📝 netbox/dcim/constants.py (+2 -2)
📝 netbox/dcim/filtersets.py (+22 -4)
📝 netbox/dcim/forms/bulk_import.py (+1 -30)
📝 netbox/dcim/forms/mixins.py (+76 -1)
📝 netbox/dcim/forms/model_forms.py (+90 -25)
📝 netbox/dcim/forms/object_create.py (+19 -122)
📝 netbox/dcim/forms/object_import.py (+21 -21)
📝 netbox/dcim/graphql/filters.py (+31 -11)
📝 netbox/dcim/graphql/types.py (+28 -4)
netbox/dcim/migrations/0222_port_mappings.py (+219 -0)
netbox/dcim/migrations/0223_frontport_positions.py (+65 -0)
netbox/dcim/models/base.py (+61 -0)
📝 netbox/dcim/models/cables.py (+66 -48)
📝 netbox/dcim/models/device_component_templates.py (+82 -46)
📝 netbox/dcim/models/device_components.py (+58 -46)
📝 netbox/dcim/models/devices.py (+5 -5)
📝 netbox/dcim/signals.py (+13 -12)

...and 15 more files

📄 Description

Closes: #20564

Note: Any changes made for FrontPort or RearPort are also made for their corresponding template models, FrontPortTemplate and RearPortTemplate, unless otherwise notes.

  • Introduce the PortMapping model to map port & position pairs between FrontPorts and RearPorts
    • This model establishes a mappings relation on both FrontPort & RearPort
  • Add a positions IntegerField on FrontPort to match the existing positions field on RearPort
  • Remove the rear_port ForeignKey and rear_port_position IntegerField from FrontPort
  • Update REST API serializers
    • Add front_ports on RearPortSerializer
    • Add rear_ports on FrontPortSerializer
  • Extend device instantiation logic to replicate all front/rear port mappings from a DeviceType to a newly created Device
    • Introduce the create_port_mappings() function for this purpose
  • Update cable tracing logic to respect positions mapped between front & rear ports
  • Update FrontPort & RearPort tables
    • Remove rear_port and rear_port_position columns from FrontPortTable
    • Add mappings column to both FrontPortTable and RearPortTable
  • Add a front_port_id filter for RearPort and update FrontPort's rear_port_id filter
  • Add positions filter for FrontPort and FrontPortTemplate
  • GraphQL API
    • Replace rear_port field on FrontPortType with mappings
    • Add mappings to RearPortType
  • Update all tests to use PortMapping for front/rear port mapping
  • Add debug logging for cable path tracing

TODO

  • Add FKs direct to Device/DeviceType on port mappings
  • Finish adapting GraphQL API (e.g. add PortMappingTemplateFilter)
  • Support mapping of front/rear ports via bulk import
  • Support port template mapping via device type import
  • Update logic for detecting split paths
  • Test setting front/rear mappings via REST API
  • Add tests to verify cable paths are updated correctly when front/rear port mappings change
  • Clean up debugging code under Cable.from_origin()

🔄 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/20851 **Author:** [@jeremystretch](https://github.com/jeremystretch) **Created:** 11/20/2025 **Status:** ✅ Merged **Merged:** 12/9/2025 **Merged by:** [@arthanson](https://github.com/arthanson) **Base:** `feature` ← **Head:** `20564-port-mappings` --- ### 📝 Commits (10+) - [`0901694`](https://github.com/netbox-community/netbox/commit/0901694b2b6f731e5a9ba669e56d6b353cdc7b6c) Initial work on FR #20788 (cable profiles) - [`a20ac40`](https://github.com/netbox-community/netbox/commit/a20ac40b487ca188fbc2a204c1facfad942f0071) Add missing filters for cable_position - [`481811e`](https://github.com/netbox-community/netbox/commit/481811e487ed4999ad3a8e0c39c7425e5a7dee16) Misc cleanup - [`7edea73`](https://github.com/netbox-community/netbox/commit/7edea73f8503b7b5bd0159333dea73d3f022d561) Add initial cable path tests for profiles - [`fe95d89`](https://github.com/netbox-community/netbox/commit/fe95d89db37d25e59f817186cfbc4c6114e38be1) Fix test - [`2fe5323`](https://github.com/netbox-community/netbox/commit/2fe5323dd2eecc6afb680de176c3714462000c36) Add topology tests for cable profiles - [`fb2ea37`](https://github.com/netbox-community/netbox/commit/fb2ea3744352375b37820e1b52d2bb45b4f999a3) Simplify A/B side popping logic - [`24c6653`](https://github.com/netbox-community/netbox/commit/24c6653356020ebd7bbe71a93189ae540d600655) Add profile for 4x4 MPO8 shuffle cable - [`a75dee7`](https://github.com/netbox-community/netbox/commit/a75dee745e93731392586d058faaa845048936b4) Enable drag-and-drop of items within multiselect fields - [`aa7eeda`](https://github.com/netbox-community/netbox/commit/aa7eedac4247a90a13a9201f576a5dfa7e5e9744) Remove many-to-one profiles ### 📊 Changes **35 files changed** (+2501 additions, -930 deletions) <details> <summary>View changed files</summary> 📝 `netbox/dcim/api/serializers_/base.py` (+52 -0) 📝 `netbox/dcim/api/serializers_/device_components.py` (+43 -18) 📝 `netbox/dcim/api/serializers_/devicetype_components.py` (+45 -8) 📝 `netbox/dcim/constants.py` (+2 -2) 📝 `netbox/dcim/filtersets.py` (+22 -4) 📝 `netbox/dcim/forms/bulk_import.py` (+1 -30) 📝 `netbox/dcim/forms/mixins.py` (+76 -1) 📝 `netbox/dcim/forms/model_forms.py` (+90 -25) 📝 `netbox/dcim/forms/object_create.py` (+19 -122) 📝 `netbox/dcim/forms/object_import.py` (+21 -21) 📝 `netbox/dcim/graphql/filters.py` (+31 -11) 📝 `netbox/dcim/graphql/types.py` (+28 -4) ➕ `netbox/dcim/migrations/0222_port_mappings.py` (+219 -0) ➕ `netbox/dcim/migrations/0223_frontport_positions.py` (+65 -0) ➕ `netbox/dcim/models/base.py` (+61 -0) 📝 `netbox/dcim/models/cables.py` (+66 -48) 📝 `netbox/dcim/models/device_component_templates.py` (+82 -46) 📝 `netbox/dcim/models/device_components.py` (+58 -46) 📝 `netbox/dcim/models/devices.py` (+5 -5) 📝 `netbox/dcim/signals.py` (+13 -12) _...and 15 more files_ </details> ### 📄 Description ### Closes: #20564 **Note:** Any changes made for FrontPort or RearPort are also made for their corresponding template models, FrontPortTemplate and RearPortTemplate, unless otherwise notes. - Introduce the `PortMapping` model to map port & position pairs between FrontPorts and RearPorts - This model establishes a `mappings` relation on both FrontPort & RearPort - Add a `positions` IntegerField on FrontPort to match the existing `positions` field on RearPort - Remove the `rear_port` ForeignKey and `rear_port_position` IntegerField from FrontPort - Update REST API serializers - Add `front_ports` on RearPortSerializer - Add `rear_ports` on FrontPortSerializer - Extend device instantiation logic to replicate all front/rear port mappings from a DeviceType to a newly created Device - Introduce the `create_port_mappings()` function for this purpose - Update cable tracing logic to respect positions mapped between front & rear ports - Update FrontPort & RearPort tables - Remove `rear_port` and `rear_port_position` columns from FrontPortTable - Add `mappings` column to both FrontPortTable and RearPortTable - Add a `front_port_id` filter for RearPort and update FrontPort's `rear_port_id` filter - Add `positions` filter for FrontPort and FrontPortTemplate - GraphQL API - Replace `rear_port` field on FrontPortType with `mappings` - Add `mappings` to RearPortType - Update all tests to use PortMapping for front/rear port mapping - Add debug logging for cable path tracing ### TODO - [x] Add FKs direct to Device/DeviceType on port mappings - [x] Finish adapting GraphQL API (e.g. add PortMappingTemplateFilter) - [ ] Support mapping of front/rear ports via bulk import - [x] Support port template mapping via device type import - [x] Update logic for detecting split paths - [x] Test setting front/rear mappings via REST API - [x] Add tests to verify cable paths are updated correctly when front/rear port mappings change - [x] Clean up debugging code under `Cable.from_origin()` --- <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:37 +01:00
adam closed this issue 2025-12-30 00:25:37 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#16069