Change format

This commit is contained in:
Ben McDonald 2025-06-12 14:54:23 -07:00
parent 4e4d00803d
commit 67f9d3e2b3
No known key found for this signature in database

View file

@ -13,41 +13,29 @@ import (
var mock bool var mock bool
func transformToSMDFormat(inventory *pdu.PDUInventory) []map[string]any { func transformToSMDFormat(inventory *pdu.PDUInventory) []map[string]any {
smdRecords := make([]map[string]any, 0) smdOutlets := make([]map[string]any, 0)
rtsHostname := fmt.Sprintf("%s-rts:8083", inventory.Hostname)
pduBank := "B"
for _, outlet := range inventory.Outlets { for _, outlet := range inventory.Outlets {
smdID := fmt.Sprintf("%sp1v%s", inventory.Hostname, outlet.ID) rawOutlet := map[string]any{
odataID := fmt.Sprintf("/redfish/v1/PowerEquipment/RackPDUs/%s/Outlets/%s", pduBank, outlet.ID) "id": outlet.ID,
redfishURL := fmt.Sprintf("%s%s", rtsHostname, odataID) "name": outlet.Name,
powerControlTarget := fmt.Sprintf("%s/Actions/Outlet.PowerControl", odataID) "state": outlet.State,
"socket_type": outlet.SocketType,
record := map[string]any{
"ID": smdID,
"Type": "CabinetPDUPowerConnector",
"RedfishType": "Outlet",
"RedfishSubtype": "Cx",
"OdataID": odataID,
"RedfishEndpointID": inventory.Hostname,
"Enabled": true,
"RedfishEndpointFQDN": rtsHostname,
"RedfishURL": redfishURL,
"ComponentEndpointType": "ComponentEndpointOutlet",
"RedfishOutletInfo": map[string]any{
"Name": outlet.Name,
"Actions": map[string]any{
"#Outlet.PowerControl": map[string]any{
"PowerState@Redfish.AllowableValues": []string{"On", "Off"},
"target": powerControlTarget,
},
},
},
} }
smdRecords = append(smdRecords, record) smdOutlets = append(smdOutlets, rawOutlet)
} }
return smdRecords
pduRecord := map[string]any{
"ID": inventory.Hostname,
"Type": "Node",
"FQDN": inventory.Hostname,
"Hostname": inventory.Hostname,
"Enabled": true,
"RediscoverOnUpdate": false,
"PDUInventory": map[string]any{
"Outlets": smdOutlets,
},
}
return []map[string]any{pduRecord}
} }
var pduCollectCmd = &cobra.Command{ var pduCollectCmd = &cobra.Command{