-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
oem/smc: introduce drive and drive action oem fields
- Loading branch information
Showing
2 changed files
with
142 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,62 @@ | ||
package smc | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/stmcginnis/gofish/redfish" | ||
) | ||
|
||
type Drive struct { | ||
redfish.Drive | ||
Oem DriveOem `json:"Oem"` | ||
} | ||
|
||
type DriveOem struct { | ||
Supermicro struct { | ||
Temperature int | ||
PercentageDriveLifeUsed int | ||
DriveFunctional bool | ||
} `json:"Supermicro"` | ||
} | ||
|
||
type DriveTarget struct { | ||
Target string `json:"target"` | ||
ActionInfo string `json:"@Redfish.ActionInfo"` | ||
} | ||
|
||
type DriveActions struct { | ||
redfish.DriveActions | ||
Oem struct { | ||
DriveIndicate DriveTarget `json:"#Drive.Indicate"` | ||
SmcDriveIndicate DriveTarget `json:"#SmcDrive.Indicate"` | ||
} `json:"Oem"` | ||
} | ||
|
||
func FromDrive(drive *redfish.Drive) (Drive, error) { | ||
var oem DriveOem | ||
err := json.Unmarshal(drive.Oem, &oem) | ||
|
||
return Drive{ | ||
Drive: *drive, | ||
Oem: oem, | ||
}, err | ||
} | ||
|
||
func FromDriveActions(da *redfish.DriveActions) (DriveActions, error) { | ||
oemActions := DriveActions{ | ||
DriveActions: *da, | ||
} | ||
|
||
err := json.Unmarshal(da.Oem, &oemActions.Oem) | ||
return oemActions, err | ||
} | ||
|
||
// DriveIndicateTarget checks both the SmcDriveIndicate and DriveIndicateTarget | ||
// Oem entries and returns the first populated target, due to key inconsistencies | ||
func (da DriveActions) DriveIndicateTarget() string { | ||
if len(da.Oem.SmcDriveIndicate.Target) > 0 { | ||
return da.Oem.SmcDriveIndicate.Target | ||
} | ||
|
||
return da.Oem.DriveIndicate.Target | ||
} |
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,80 @@ | ||
package smc | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stmcginnis/gofish/redfish" | ||
) | ||
|
||
var smcDriveBody = `{ | ||
"@odata.type": "#Drive.v1_6_2.Drive", | ||
"@odata.id": "/redfish/v1/Chassis/NVMeSSD.0.Group.0.StorageBackplane/Drives/Disk.Bay.22", | ||
"Name": "Disk.Bay.22", | ||
"Id": "22", | ||
"Manufacturer": "INTEL", | ||
"SerialNumber": "PHLWOOFMEOWIAMCATDOG", | ||
"Model": "INTEL SSDPE2KX080T8O", | ||
"StatusIndicator": "OK", | ||
"FailurePredicted": false, | ||
"CapacityBytes": 8001563222016, | ||
"CapableSpeedGbs": 31.5, | ||
"Oem": { | ||
"Supermicro": { | ||
"@odata.type": "#SmcDriveExtensions.v1_0_0.Drive", | ||
"Temperature": 33, | ||
"PercentageDriveLifeUsed": 3, | ||
"DriveFunctional": true | ||
} | ||
}, | ||
"IndicatorLED": "Off", | ||
"Status": { | ||
"State": "Enabled", | ||
"Health": "OK" | ||
}, | ||
"Links": { | ||
"Volumes": [] | ||
}, | ||
"Actions": { | ||
"Oem": { | ||
"#Drive.Indicate": { | ||
"target": "/redfish/v1/Chassis/NVMeSSD.0.Group.0.StorageBackplane/Drives/Disk.Bay.22/Actions/Oem/Drive.Indicate", | ||
"@Redfish.ActionInfo": "/redfish/v1/Chassis/NVMeSSD.0.Group.0.StorageBackplane/Drives/Disk.Bay.22/IndicateActionInfo" | ||
} | ||
} | ||
} | ||
}` | ||
|
||
// TestSmcDriveOem tests the parsing of the Drive oem field | ||
func TestSmcDriveOem(t *testing.T) { | ||
drive := &redfish.Drive{} | ||
if err := json.Unmarshal([]byte(smcDriveBody), drive); err != nil { | ||
t.Fatalf("error decoding json: %v", err) | ||
} | ||
|
||
smcDrive, err := FromDrive(drive) | ||
if err != nil { | ||
t.Fatalf("error getting oem info from drive: %v", err) | ||
} | ||
|
||
if smcDrive.Oem.Supermicro.Temperature != 33 { | ||
t.Errorf("unexpected oem drive temerature: %d", smcDrive.Oem.Supermicro.Temperature) | ||
} | ||
} | ||
|
||
// TestSmcDriveActionOem tests the parsing of the Drive Actions field | ||
func TestSmcDriveActionOem(t *testing.T) { | ||
drive := &redfish.Drive{} | ||
if err := json.Unmarshal([]byte(smcDriveBody), drive); err != nil { | ||
t.Fatalf("error decoding json: %v", err) | ||
} | ||
|
||
smcDriveActions, err := FromDriveActions(&drive.Actions) | ||
if err != nil { | ||
t.Fatalf("error getting oem info from drive: %v", err) | ||
} | ||
|
||
if smcDriveActions.DriveIndicateTarget() != "/redfish/v1/Chassis/NVMeSSD.0.Group.0.StorageBackplane/Drives/Disk.Bay.22/Actions/Oem/Drive.Indicate" { | ||
t.Errorf("unexpected oem drive indicator target: %s", smcDriveActions.DriveIndicateTarget()) | ||
} | ||
} |