fix(redfish): support composed G894 inventory
This commit is contained in:
1 parent
ab53914d0a
commit
3ac19f37b8
6 files changed
+536
-12
No files matched your search
@@ -37,8 +37,9 @@ func ReplayRedfishFromRawPayloads(rawPayloads map[string]any, emit ProgressFn) (
|
||||
|
||||
systemPaths := r.discoverMemberPaths("/redfish/v1/Systems", "/redfish/v1/Systems/1")
|
||||
chassisPaths := r.discoverMemberPaths("/redfish/v1/Chassis", "/redfish/v1/Chassis/1")
|
||||
chassisPaths = r.appendSystemLinkedChassisPaths(systemPaths, chassisPaths)
|
||||
managerPaths := r.discoverMemberPaths("/redfish/v1/Managers", "/redfish/v1/Managers/1")
|
||||
primarySystem := firstPathOrDefault(systemPaths, "/redfish/v1/Systems/1")
|
||||
primarySystem := r.selectHostSystemPath(systemPaths, "/redfish/v1/Systems/1")
|
||||
primaryChassis := firstPathOrDefault(chassisPaths, "/redfish/v1/Chassis/1")
|
||||
primaryManager := firstPathOrDefault(managerPaths, "/redfish/v1/Managers/1")
|
||||
|
||||
@@ -70,18 +71,33 @@ func ReplayRedfishFromRawPayloads(rawPayloads map[string]any, emit ProgressFn) (
|
||||
if emit != nil {
|
||||
emit(Progress{Status: "running", Progress: 55, Message: "Redfish snapshot: replay CPU/RAM/Storage..."})
|
||||
}
|
||||
processors := r.collectProcessors(primarySystem)
|
||||
memory := r.collectMemory(primarySystem)
|
||||
storageDevices := r.collectStorage(primarySystem, analysisPlan)
|
||||
storageVolumes := r.collectStorageVolumes(primarySystem, analysisPlan)
|
||||
var processors []models.CPU
|
||||
var memory []models.MemoryDIMM
|
||||
var storageDevices []models.Storage
|
||||
var storageVolumes []models.StorageVolume
|
||||
var storageControllers []models.PCIeDevice
|
||||
for _, systemPath := range systemPaths {
|
||||
processors = append(processors, r.collectProcessors(systemPath)...)
|
||||
memory = append(memory, r.collectMemory(systemPath)...)
|
||||
storageDevices = append(storageDevices, r.collectStorage(systemPath, analysisPlan)...)
|
||||
storageVolumes = append(storageVolumes, r.collectStorageVolumes(systemPath, analysisPlan)...)
|
||||
storageControllers = append(storageControllers, r.collectStorageControllers(systemPath)...)
|
||||
}
|
||||
processors = dedupeReplayCPUs(processors)
|
||||
storageDevices = dedupeStorage(storageDevices)
|
||||
storageVolumes = dedupeStorageVolumes(storageVolumes)
|
||||
|
||||
if emit != nil {
|
||||
emit(Progress{Status: "running", Progress: 80, Message: "Redfish snapshot: replay network/BMC..."})
|
||||
}
|
||||
psus := r.collectPSUs(chassisPaths)
|
||||
psuChassisPaths := dedupeRedfishPaths(redfishLinkRefs(systemDoc, "Links", "Chassis"))
|
||||
psus := r.collectPSUs(psuChassisPaths)
|
||||
if len(psus) == 0 {
|
||||
psus = r.collectPSUs(chassisPaths)
|
||||
}
|
||||
licenses := r.collectLicenses()
|
||||
pcieDevices := r.collectPCIeDevices(systemPaths, chassisPaths)
|
||||
pcieDevices = append(pcieDevices, r.collectStorageControllers(primarySystem)...)
|
||||
pcieDevices = dedupePCIeDevices(append(pcieDevices, storageControllers...))
|
||||
boardInfo := parseBoardInfoWithFallback(systemDoc, chassisDoc, fruDoc)
|
||||
applyBoardInfoFallbackFromDocs(&boardInfo, boardFallbackDocs)
|
||||
|
||||
@@ -89,6 +105,7 @@ func ReplayRedfishFromRawPayloads(rawPayloads map[string]any, emit ProgressFn) (
|
||||
gpus = r.collectGPUsFromProcessors(systemPaths, chassisPaths, gpus, analysisPlan)
|
||||
nics := r.collectNICs(chassisPaths)
|
||||
r.enrichNICsFromNetworkInterfaces(&nics, systemPaths)
|
||||
standardSensors := r.collectStandardSensors(chassisPaths)
|
||||
thresholdSensors := r.collectThresholdSensors(chassisPaths)
|
||||
thermalSensors := r.collectThermalSensors(chassisPaths)
|
||||
powerSensors := r.collectPowerSensors(chassisPaths)
|
||||
@@ -117,7 +134,7 @@ func ReplayRedfishFromRawPayloads(rawPayloads map[string]any, emit ProgressFn) (
|
||||
SourceTimezone: sourceTimezone,
|
||||
Events: append(append(append(append(append(append(make([]models.Event, 0, len(discreteEvents)+len(healthEvents)+len(driveFetchWarningEvents)+len(logEntryEvents)+len(sensorHintEvents)+2), healthEvents...), discreteEvents...), driveFetchWarningEvents...), logEntryEvents...), sensorHintEvents...), bmcManagementEvent...),
|
||||
FRU: assemblyFRU,
|
||||
Sensors: dedupeSensorReadings(append(append(thresholdSensors, thermalSensors...), powerSensors...)),
|
||||
Sensors: dedupeSensorReadings(append(append(append(standardSensors, thresholdSensors...), thermalSensors...), powerSensors...)),
|
||||
RawPayloads: cloneRawPayloads(rawPayloads),
|
||||
Hardware: &models.HardwareConfig{
|
||||
BoardInfo: boardInfo,
|
||||
@@ -609,6 +626,42 @@ func (r redfishSnapshotReader) collectThresholdSensors(chassisPaths []string) []
|
||||
return out
|
||||
}
|
||||
|
||||
func (r redfishSnapshotReader) collectStandardSensors(chassisPaths []string) []models.SensorReading {
|
||||
var out []models.SensorReading
|
||||
for _, chassisPath := range chassisPaths {
|
||||
docs, err := r.getCollectionMembers(joinPath(chassisPath, "/Sensors"))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
for _, doc := range docs {
|
||||
if sensor, ok := parseThresholdSensor(doc); ok {
|
||||
out = append(out, sensor)
|
||||
}
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func dedupeReplayCPUs(items []models.CPU) []models.CPU {
|
||||
if len(items) <= 1 {
|
||||
return items
|
||||
}
|
||||
out := make([]models.CPU, 0, len(items))
|
||||
seen := make(map[string]struct{}, len(items))
|
||||
for _, item := range items {
|
||||
key := normalizeRedfishIdentityField(item.SerialNumber)
|
||||
if key == "" {
|
||||
key = fmt.Sprintf("socket:%d|model:%s|cores:%d|threads:%d", item.Socket, strings.ToLower(strings.TrimSpace(item.Model)), item.Cores, item.Threads)
|
||||
}
|
||||
if _, ok := seen[key]; ok {
|
||||
continue
|
||||
}
|
||||
seen[key] = struct{}{}
|
||||
out = append(out, item)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func parseThresholdSensor(doc map[string]interface{}) (models.SensorReading, bool) {
|
||||
if len(doc) == 0 {
|
||||
return models.SensorReading{}, false
|
||||
@@ -1219,6 +1272,99 @@ func (r redfishSnapshotReader) discoverMemberPaths(collectionPath, fallbackPath
|
||||
return nil
|
||||
}
|
||||
|
||||
// selectHostSystemPath chooses the server/host ComputerSystem independently of
|
||||
// collection order. Composed accelerator platforms can expose an HGX system
|
||||
// before the host system, while CPU, BIOS, and server identity live on another
|
||||
// member such as Systems/Self.
|
||||
func (r redfishSnapshotReader) selectHostSystemPath(paths []string, fallback string) string {
|
||||
bestPath := ""
|
||||
bestScore := -1
|
||||
for _, path := range paths {
|
||||
path = strings.TrimSpace(path)
|
||||
if path == "" {
|
||||
continue
|
||||
}
|
||||
doc, err := r.getJSON(path)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
processorDocs, _ := r.getCollectionMembers(joinPath(path, "/Processors"))
|
||||
score := redfishHostSystemScore(path, doc, processorDocs)
|
||||
if score > bestScore {
|
||||
bestPath = path
|
||||
bestScore = score
|
||||
}
|
||||
}
|
||||
if bestPath != "" {
|
||||
return bestPath
|
||||
}
|
||||
return firstPathOrDefault(paths, fallback)
|
||||
}
|
||||
|
||||
func (r redfishSnapshotReader) appendSystemLinkedChassisPaths(systemPaths, chassisPaths []string) []string {
|
||||
out := append([]string{}, chassisPaths...)
|
||||
for _, systemPath := range systemPaths {
|
||||
doc, err := r.getJSON(systemPath)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
out = append(out, redfishLinkRefs(doc, "Links", "Chassis")...)
|
||||
}
|
||||
return dedupeRedfishPaths(out)
|
||||
}
|
||||
|
||||
func dedupeRedfishPaths(paths []string) []string {
|
||||
out := make([]string, 0, len(paths))
|
||||
seen := make(map[string]struct{}, len(paths))
|
||||
for _, path := range paths {
|
||||
path = normalizeRedfishPath(path)
|
||||
if path == "" {
|
||||
continue
|
||||
}
|
||||
if _, ok := seen[path]; ok {
|
||||
continue
|
||||
}
|
||||
seen[path] = struct{}{}
|
||||
out = append(out, path)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func redfishHostSystemScore(path string, doc map[string]interface{}, processorDocs []map[string]interface{}) int {
|
||||
score := 0
|
||||
if strings.EqualFold(lastRedfishPathSegment(path), "self") {
|
||||
score += 25
|
||||
}
|
||||
if summary, ok := doc["ProcessorSummary"].(map[string]interface{}); ok && asInt(summary["Count"]) > 0 {
|
||||
score += 80
|
||||
}
|
||||
if redfishLinkedPath(doc, "Bios") != "" {
|
||||
score += 40
|
||||
}
|
||||
if _, ok := doc["Boot"].(map[string]interface{}); ok {
|
||||
score += 20
|
||||
}
|
||||
if strings.TrimSpace(asString(doc["HostName"])) != "" {
|
||||
score += 10
|
||||
}
|
||||
for _, processor := range processorDocs {
|
||||
processorType := strings.TrimSpace(asString(processor["ProcessorType"]))
|
||||
if processorType == "" || strings.EqualFold(processorType, "CPU") || strings.EqualFold(processorType, "General") {
|
||||
score += 100
|
||||
break
|
||||
}
|
||||
}
|
||||
return score
|
||||
}
|
||||
|
||||
func lastRedfishPathSegment(path string) string {
|
||||
path = strings.Trim(strings.TrimSpace(path), "/")
|
||||
if idx := strings.LastIndex(path, "/"); idx >= 0 {
|
||||
return path[idx+1:]
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
func (r redfishSnapshotReader) getLinkedPCIeFunctions(doc map[string]interface{}) []map[string]interface{} {
|
||||
if links, ok := doc["Links"].(map[string]interface{}); ok {
|
||||
if refs, ok := links["PCIeFunctions"].([]interface{}); ok && len(refs) > 0 {
|
||||
|
||||
Reference in new issue
Block a user