mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 03:27:03 -07:00
Switch to standard xname
This commit is contained in:
parent
6b3d317086
commit
dc09b7051d
1 changed files with 22 additions and 4 deletions
|
|
@ -3,6 +3,8 @@ package cmd
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"unicode"
|
||||||
|
|
||||||
"github.com/OpenCHAMI/magellan/pkg/jaws"
|
"github.com/OpenCHAMI/magellan/pkg/jaws"
|
||||||
"github.com/OpenCHAMI/magellan/pkg/pdu"
|
"github.com/OpenCHAMI/magellan/pkg/pdu"
|
||||||
|
|
@ -10,16 +12,32 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var mock bool
|
|
||||||
|
|
||||||
func transformToSMDFormat(inventory *pdu.PDUInventory) []map[string]any {
|
func transformToSMDFormat(inventory *pdu.PDUInventory) []map[string]any {
|
||||||
smdOutlets := make([]map[string]any, 0)
|
smdOutlets := make([]map[string]any, 0)
|
||||||
for _, outlet := range inventory.Outlets {
|
for _, outlet := range inventory.Outlets {
|
||||||
|
var letterPart, numberPart string
|
||||||
|
splitIndex := strings.IndexFunc(outlet.ID, unicode.IsDigit)
|
||||||
|
|
||||||
|
if splitIndex == -1 {
|
||||||
|
log.Warn().Msgf("could not parse outlet ID format for '%s', skipping outlet", outlet.ID)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
letterPart = outlet.ID[:splitIndex]
|
||||||
|
numberPart = outlet.ID[splitIndex:]
|
||||||
|
|
||||||
|
var pValue int
|
||||||
|
if len(letterPart) > 1 {
|
||||||
|
pValue = int(unicode.ToUpper(rune(letterPart[1])) - 'A')
|
||||||
|
}
|
||||||
|
|
||||||
|
newIDSuffix := fmt.Sprintf("p%dv%s", pValue, numberPart)
|
||||||
|
|
||||||
rawOutlet := map[string]any{
|
rawOutlet := map[string]any{
|
||||||
"id": outlet.ID,
|
"id": newIDSuffix, // Pass the newly formatted suffix to SMD
|
||||||
"name": outlet.Name,
|
"name": outlet.Name,
|
||||||
"state": outlet.PowerState,
|
"state": outlet.PowerState,
|
||||||
"socket_type": "Cx",
|
"socket_type": "Cx", // This seems to be static
|
||||||
}
|
}
|
||||||
smdOutlets = append(smdOutlets, rawOutlet)
|
smdOutlets = append(smdOutlets, rawOutlet)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue