mirror of
https://github.com/netbox-community/netbox.git
synced 2026-04-10 11:23:58 +02:00
Implement {module} position inheritance for nested module bays (#21753)
* Implement {module} position inheritance for nested module bays (#19796)
Enables a single ModuleType to produce correctly named components at any
nesting depth by resolving {module} in module bay position fields during
tree traversal. The user controls the separator through the position
field template itself (e.g. {module}/1 vs {module}-1 vs {module}.1).
Model layer:
- Add _get_inherited_positions() to resolve {module} in positions as
the module tree is walked from root to leaf
- Update _resolve_module_placeholder() with single-token logic: one
{module} resolves to the leaf bay's inherited position; multi-token
continues level-by-level replacement for backwards compatibility
Form layer:
- Update _get_module_bay_tree() to resolve {module} in positions during
traversal, propagating parent positions through the tree
- Extract validation into _validate_module_tokens() private method
Tests:
- Position inheritance at depth 2 and 3
- Custom separator (dot notation)
- Multi-token backwards compatibility
- Documentation for position inheritance
Fixes: #19796
* Consolidate {module} placeholder logic into shared utilities and add API validation
Extract get_module_bay_positions() and resolve_module_placeholder() into
dcim/utils.py as shared routines used by the model, form, and API serializer.
This eliminates duplicated traversal and resolution logic across three layers.
Key changes:
- Add position inheritance: {module} tokens in bay position fields resolve
using the parent bay's position during hierarchy traversal
- Single {module} token now resolves to the leaf bay's inherited position
- Mismatched token count vs tree depth now raises ValueError instead of
silently producing partial strings
- API serializer validation uses shared utilities for parity with the form
- Fix error message wording ("levels deep" instead of "in tree")
This commit is contained in:
committed by
GitHub
parent
b62c5e1ac4
commit
a06a300913
@@ -32,6 +32,26 @@ For example, `{vc_position:1}` will render as `1` when no Virtual Chassis positi
|
||||
|
||||
Automatic renaming is supported for all modular component types (those listed above).
|
||||
|
||||
### Position Inheritance for Nested Modules
|
||||
|
||||
When using nested module bays (modules installed inside other modules), the `{module}` placeholder
|
||||
can also be used in the **position** field of module bay templates to inherit the parent bay's
|
||||
position. This allows a single module type to produce correctly named components at any nesting
|
||||
depth, with a user-controlled separator.
|
||||
|
||||
For example, a line card module type might define sub-bay positions as `{module}/1`, `{module}/2`,
|
||||
etc. When the line card is installed in a device bay with position `3`, these sub-bay positions
|
||||
resolve to `3/1`, `3/2`, etc. An SFP module type with interface template `SFP {module}` installed
|
||||
in sub-bay `3/2` then produces interface `SFP 3/2`.
|
||||
|
||||
The separator between levels is defined by the user in the position field template itself. Using
|
||||
`{module}-1` produces positions like `3-1`, while `{module}.1` produces `3.1`. This provides
|
||||
full flexibility without requiring a global separator configuration.
|
||||
|
||||
!!! note
|
||||
If the position field does not contain `{module}`, no inheritance occurs and behavior is
|
||||
unchanged from previous versions.
|
||||
|
||||
## Fields
|
||||
|
||||
### Manufacturer
|
||||
|
||||
Reference in New Issue
Block a user