Skip to content

Commit

Permalink
Add ProcessorSummary Metrics link (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwieczorek authored Nov 29, 2024
1 parent c960693 commit e5cf8b6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
32 changes: 32 additions & 0 deletions redfish/computersystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
10 changes: 9 additions & 1 deletion redfish/computersystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit e5cf8b6

Please sign in to comment.