Merge pull request #1826 from anderbubble/fix-dotted-netdev

Fix display of dotted field names
This commit is contained in:
Jonathon Anderson
2025-03-21 10:29:45 -06:00
committed by GitHub
3 changed files with 53 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Replaced unreadable >= character external sphinx module for pdf doc build.
- Handle missing ipmi fields during bmc commands. #1768
- Properly configure a default IPMI template during `wwctl upgrade nodes --add-defaults`.
- Fixed display of dotted field names. #1825
### Changed

View File

@@ -114,7 +114,7 @@ func getNestedFieldValue(obj interface{}, name string) (value reflect.Value, err
value = value.Elem()
}
fieldNames := strings.Split(name, ".")
fieldNames := splitFieldName(name)
for _, fieldName := range fieldNames {
var key string
fieldName, key = parseMapField(fieldName)
@@ -141,6 +141,45 @@ func getNestedFieldValue(obj interface{}, name string) (value reflect.Value, err
return
}
// splitName splits a string into components using the '.' character as a delimiter,
// except when the '.' appears inside square brackets.
//
// For example, given the input "NetDevs[eth0.100].Type", it returns:
//
// []string{"NetDevs[eth0.100]", "Type"}
func splitFieldName(s string) []string {
var parts []string
var current []rune
inBracket := false
for _, r := range s {
switch r {
case '[':
inBracket = true
current = append(current, r)
case ']':
inBracket = false
current = append(current, r)
case '.':
if inBracket {
// If we're inside brackets, keep the dot.
current = append(current, r)
} else {
// Outside brackets, split here.
parts = append(parts, string(current))
current = nil
}
default:
current = append(current, r)
}
}
// Append any remaining characters as the last part.
if len(current) > 0 {
parts = append(parts, string(current))
}
return parts
}
// getNestedFieldString retrieves the string representation
// of a nested field as returned by getNestedFieldValue.
//

View File

@@ -672,6 +672,18 @@ nodeprofiles:
source: "",
value: "p1,p2",
},
"dotted netdev name": {
nodesConf: `
nodes:
n1:
network devices:
eth0.100:
type: Ethernet`,
node: "n1",
field: "NetDevs[eth0.100].Type",
source: "",
value: "Ethernet",
},
"node netdev tag": {
nodesConf: `
nodes: