Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ProcessorSummary Metrics link #386

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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