Closes #20564: Many-to-many pass-through port mappings #838

Closed
opened 2026-04-05 18:05:31 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @jeremystretch on 11/20/2025

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()
*Originally created by @jeremystretch on 11/20/2025* ### 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()`
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/netbox#838