From e5cf8b6613e8c7b484a36c6826b54f5c2dd1c2bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Wieczorek?= <7051680+mwieczorek@users.noreply.github.com> Date: Fri, 29 Nov 2024 18:48:10 +0100 Subject: [PATCH] Add ProcessorSummary Metrics link (#386) --- redfish/computersystem.go | 32 ++++++++++++++++++++++++++++++++ redfish/computersystem_test.go | 10 +++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/redfish/computersystem.go b/redfish/computersystem.go index f4d7ac0a..d1de79d8 100644 --- a/redfish/computersystem.go +++ b/redfish/computersystem.go @@ -1341,6 +1341,9 @@ type ProcessorSummary struct { Count int // LogicalProcessorCount is the number of logical central processors in the system. LogicalProcessorCount int + // Metrics shall be a reference to the Metrics + // associated with this ProcessorSummary. + metrics string // Model is the processor model for the central processors in the system, // per the description in the Processor Information - Processor Family // section of the SMBIOS Specification DSP0134 2.8 or later. @@ -1349,6 +1352,35 @@ type ProcessorSummary struct { Status common.Status } +// UnmarshalJSON unmarshals a ProcessorSummary object from the raw JSON. +func (processorSummary *ProcessorSummary) UnmarshalJSON(b []byte) error { + type temp ProcessorSummary + type t1 struct { + temp + Metrics common.Link + } + var t t1 + + err := json.Unmarshal(b, &t) + if err != nil { + return err + } + + *processorSummary = ProcessorSummary(t.temp) + + processorSummary.metrics = t.Metrics.String() + + return nil +} + +// Metrics gets the processor summary metrics +func (processorSummary *ProcessorSummary) Metrics(c common.Client) (*ProcessorMetrics, error) { + if processorSummary.metrics == "" { + return nil, nil + } + return GetProcessorMetrics(c, processorSummary.metrics) +} + // TrustedModules is This type shall describe a trusted module for a system. type TrustedModules struct { // FirmwareVersion is the firmware version as diff --git a/redfish/computersystem_test.go b/redfish/computersystem_test.go index 7ed034a8..29311bb9 100644 --- a/redfish/computersystem_test.go +++ b/redfish/computersystem_test.go @@ -88,7 +88,10 @@ var computerSystemBody = `{ "State": "Enabled" }, "Count": 2, - "Model": "Multi-Core Intel(R) Xeon(R) processor 7500 Series" + "Model": "Multi-Core Intel(R) Xeon(R) processor 7500 Series", + "Metrics": { + "@odata.id": "/redfish/v1/Systems/System-1/ProcessorSummary/ProcessorMetrics" + } }, "MemorySummary": { "Status": { @@ -275,6 +278,11 @@ func TestComputerSystem(t *testing.T) { //nolint result.TrustedModules[0].InterfaceTypeSelection) } + if result.ProcessorSummary.metrics != "/redfish/v1/Systems/System-1/ProcessorSummary/ProcessorMetrics" { + t.Errorf("Received invalid processor summary metrics: %s", + result.ProcessorSummary.metrics) + } + if result.processors != "/redfish/v1/Systems/System-1/Processors" { t.Errorf("Received invalid processors reference: %s", result.processors) }