-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support oem field of thermal and fan (#178)
Co-authored-by: haoli <[email protected]>
- Loading branch information
Showing
3 changed files
with
188 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,75 @@ | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// | ||
|
||
package hpe | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/stmcginnis/gofish/redfish" | ||
) | ||
|
||
func FromThermal(thermal *redfish.Thermal) (Thermal, error) { | ||
oem := ThermalOem{} | ||
|
||
_ = json.Unmarshal(thermal.Oem, &oem) | ||
|
||
fans := make([]Fan, 0, len(thermal.Fans)) | ||
|
||
for i := range thermal.Fans { | ||
fan, err := FromFan(&thermal.Fans[i]) | ||
if err != nil { | ||
return Thermal{}, err | ||
} | ||
|
||
fans = append(fans, fan) | ||
} | ||
|
||
return Thermal{ | ||
Thermal: *thermal, | ||
Fans: fans, | ||
Oem: oem, | ||
}, nil | ||
} | ||
|
||
func FromFan(fan *redfish.Fan) (Fan, error) { | ||
oem := FanOem{} | ||
|
||
_ = json.Unmarshal(fan.Oem, &oem) | ||
|
||
return Fan{ | ||
Fan: *fan, | ||
Oem: oem, | ||
}, nil | ||
} | ||
|
||
type Fan struct { | ||
redfish.Fan | ||
Oem FanOem | ||
} | ||
|
||
type FanOem struct { | ||
Hpe struct { | ||
OdataContext string `json:"@odata.context"` | ||
OdataType string `json:"@odata.type"` | ||
Location string `json:"Location"` | ||
Redundant bool `json:"Redundant"` | ||
HotPluggable bool `json:"HotPluggable"` | ||
} `json:"Hpe"` | ||
} | ||
|
||
type Thermal struct { | ||
redfish.Thermal | ||
Fans []Fan | ||
Oem ThermalOem | ||
} | ||
|
||
type ThermalOem struct { | ||
Hpe struct { | ||
OdataContext string `json:"@odata.context"` | ||
OdataType string `json:"@odata.type"` | ||
ThermalConfiguration string `json:"ThermalConfiguration"` | ||
FanPercentMinimum int `json:"FanPercentMinimum"` | ||
} `json:"Hpe"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,105 @@ | ||
// | ||
// SPDX-License-Identifier: BSD-3-Clause | ||
// | ||
|
||
package hpe | ||
|
||
import ( | ||
"encoding/json" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stmcginnis/gofish/redfish" | ||
) | ||
|
||
var hpeThermalBody = `{ | ||
"@odata.context": "/redfish/v1/$metadata#Thermal.Thermal", | ||
"@odata.etag": "W/\"AEC0B081\"", | ||
"@odata.id": "/redfish/v1/Chassis/1/Thermal/", | ||
"@odata.type": "#Thermal.v1_1_0.Thermal", | ||
"Id": "Thermal", | ||
"Fans": [ | ||
{ | ||
"@odata.id": "/redfish/v1/Chassis/1/Thermal/#Fans/0", | ||
"MemberId": "0", | ||
"Name": "Fan 1", | ||
"Oem": { | ||
"Hpe": { | ||
"@odata.context": "/redfish/v1/$metadata#HpeServerFan.HpeServerFan", | ||
"@odata.type": "#HpeServerFan.v2_0_0.HpeServerFan", | ||
"HotPluggable": true, | ||
"Location": "System", | ||
"Redundant": true | ||
} | ||
}, | ||
"Reading": 28, | ||
"ReadingUnits": "Percent", | ||
"Status": { | ||
"Health": "OK", | ||
"State": "Enabled" | ||
} | ||
} | ||
], | ||
"Name": "Thermal", | ||
"Oem": { | ||
"Hpe": { | ||
"@odata.context": "/redfish/v1/$metadata#HpeThermalExt.HpeThermalExt", | ||
"@odata.type": "#HpeThermalExt.v2_0_0.HpeThermalExt", | ||
"FanPercentMinimum": 15, | ||
"ThermalConfiguration": "OptimalCooling" | ||
} | ||
}, | ||
"Temperatures": [ | ||
{ | ||
"@odata.id": "/redfish/v1/Chassis/1/Thermal/#Temperatures/0", | ||
"MemberId": "0", | ||
"Name": "01-Inlet Ambient", | ||
"Oem": { | ||
"Hpe": { | ||
"@odata.context": "/redfish/v1/$metadata#HpeSeaOfSensors.HpeSeaOfSensors", | ||
"@odata.type": "#HpeSeaOfSensors.v2_0_0.HpeSeaOfSensors", | ||
"LocationXmm": 15, | ||
"LocationYmm": 0 | ||
} | ||
}, | ||
"PhysicalContext": "Intake", | ||
"ReadingCelsius": 25, | ||
"SensorNumber": 1, | ||
"Status": { | ||
"Health": "OK", | ||
"State": "Enabled" | ||
}, | ||
"UpperThresholdCritical": 42, | ||
"UpperThresholdFatal": 47, | ||
"UpperThresholdUser": 0 | ||
} | ||
] | ||
}` | ||
|
||
// TestHpeThermalOem tests the parsing of Thermal objects and support oem field. | ||
func TestHpeThermalOem(t *testing.T) { | ||
var thermal *redfish.Thermal | ||
err := json.NewDecoder(strings.NewReader(hpeThermalBody)).Decode(&thermal) | ||
|
||
if err != nil { | ||
t.Errorf("Error decoding JSON: %s", err) | ||
} | ||
|
||
hpeThermal, err := FromThermal(thermal) | ||
if err != nil { | ||
t.Errorf("Convert thermal failed: %s", err) | ||
return | ||
} | ||
|
||
if hpeThermal.Oem.Hpe.FanPercentMinimum != 15 { | ||
t.Errorf("Received invalid fan fan percent minimum: %d", hpeThermal.Oem.Hpe.FanPercentMinimum) | ||
} | ||
|
||
if hpeThermal.Oem.Hpe.ThermalConfiguration != "OptimalCooling" { | ||
t.Errorf("Received invalid hpeThermal configuration: %s", hpeThermal.Oem.Hpe.ThermalConfiguration) | ||
} | ||
|
||
if hpeThermal.Fans[0].Oem.Hpe.Location != "System" { | ||
t.Errorf("Received invalid location: %s", hpeThermal.Fans[0].Oem.Hpe.Location) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,6 109,10 @@ type Fan struct { | |
// range but is not critical. The units shall be the same units as the | ||
// related Reading property. | ||
UpperThresholdNonCritical float32 | ||
// Oem shall contain the OEM extensions. All values for properties that | ||
// this object contains shall conform to the Redfish Specification | ||
// described requirements. | ||
Oem json.RawMessage | ||
} | ||
|
||
// UnmarshalJSON unmarshals a Fan object from the raw JSON. | ||
|
@@ -281,6 285,10 @@ type Thermal struct { | |
Temperatures []Temperature | ||
// TemperaturesCount is the number of Temperature objects | ||
TemperaturesCount int `json:"[email protected]"` | ||
// Oem shall contain the OEM extensions. All values for properties that | ||
// this object contains shall conform to the Redfish Specification | ||
// described requirements. | ||
Oem json.RawMessage | ||
// rawData holds the original serialized JSON so we can compare updates. | ||
rawData []byte | ||
} | ||
|