Skip to content

Commit f8feb2d

Browse files
committed
oem/smc: address some feedback
Signed-off-by: Matt Vandermeulen <[email protected]>
1 parent 39cf834 commit f8feb2d

File tree

2 files changed

+54
-41
lines changed

2 files changed

+54
-41
lines changed

oem/smc/drive.go

+50-24
Original file line numberDiff line numberDiff line change
@@ -6,57 +6,83 @@ import (
66
"github.com/stmcginnis/gofish/redfish"
77
)
88

9+
// Drive extends a redfish.Drive for additional OEM fields
910
type Drive struct {
1011
redfish.Drive
11-
Oem DriveOem `json:"Oem"`
12+
smc struct {
13+
Oem driveOem `json:"Oem"`
14+
Actions driveActions `json:"Actions"`
15+
}
1216
}
1317

14-
type DriveOem struct {
18+
type driveOem struct {
1519
Supermicro struct {
1620
Temperature int
1721
PercentageDriveLifeUsed int
1822
DriveFunctional bool
1923
} `json:"Supermicro"`
2024
}
2125

22-
type DriveTarget struct {
26+
type driveTarget struct {
2327
Target string `json:"target"`
2428
ActionInfo string `json:"@Redfish.ActionInfo"`
2529
}
2630

27-
type DriveActions struct {
31+
type driveActions struct {
2832
redfish.DriveActions
2933
Oem struct {
30-
DriveIndicate DriveTarget `json:"#Drive.Indicate"`
31-
SmcDriveIndicate DriveTarget `json:"#SmcDrive.Indicate"`
34+
DriveIndicate driveTarget `json:"#Drive.Indicate"`
35+
SmcDriveIndicate driveTarget `json:"#SmcDrive.Indicate"`
3236
} `json:"Oem"`
3337
}
3438

39+
// FromDrive returns an OEM-extended redfish drive
3540
func FromDrive(drive *redfish.Drive) (Drive, error) {
36-
var oem DriveOem
37-
err := json.Unmarshal(drive.Oem, &oem)
38-
39-
return Drive{
41+
smcDrive := Drive{
4042
Drive: *drive,
41-
Oem: oem,
42-
}, err
43-
}
43+
}
44+
smcDrive.smc.Actions.DriveActions = drive.Actions
4445

45-
func FromDriveActions(da *redfish.DriveActions) (DriveActions, error) {
46-
oemActions := DriveActions{
47-
DriveActions: *da,
46+
if err := json.Unmarshal(drive.Oem, &smcDrive.smc.Oem); err != nil {
47+
return smcDrive, err
4848
}
4949

50-
err := json.Unmarshal(da.Oem, &oemActions.Oem)
51-
return oemActions, err
50+
if err := json.Unmarshal(drive.Actions.Oem, &smcDrive.smc.Actions.Oem); err != nil {
51+
return smcDrive, err
52+
}
53+
54+
return smcDrive, nil
55+
}
56+
57+
// Temperature returns the OEM provided temperature for the drive
58+
func (d Drive) Temperature() int {
59+
return d.smc.Oem.Supermicro.Temperature
60+
}
61+
62+
// PercentageDriveLifeUsed returns the OEM provided drive life estimate as a percentage used
63+
func (d Drive) PercentageDriveLifeUsed() int {
64+
return d.smc.Oem.Supermicro.PercentageDriveLifeUsed
5265
}
5366

54-
// DriveIndicateTarget checks both the SmcDriveIndicate and DriveIndicateTarget
55-
// Oem entries and returns the first populated target, due to key inconsistencies
56-
func (da DriveActions) DriveIndicateTarget() string {
57-
if len(da.Oem.SmcDriveIndicate.Target) > 0 {
58-
return da.Oem.SmcDriveIndicate.Target
67+
// Functional returns the OEM provided flag that suggests whether a drive is functional or not
68+
func (d Drive) Functional() bool {
69+
return d.smc.Oem.Supermicro.DriveFunctional
70+
}
71+
72+
// indicateTarget figures out what uri to follow for indicator light actions.
73+
// This is a separate function for testing.
74+
func (d Drive) indicateTarget() string {
75+
// We check both the SmcDriveIndicate and the DriveIndicate targets
76+
// in the Oem sections - certain models and bmc firmwares will mix
77+
// these up, so we check both
78+
if len(d.smc.Actions.Oem.SmcDriveIndicate.Target) > 0 {
79+
return d.smc.Actions.Oem.SmcDriveIndicate.Target
5980
}
6081

61-
return da.Oem.DriveIndicate.Target
82+
return d.smc.Actions.Oem.DriveIndicate.Target
83+
}
84+
85+
// Indicate will set the indicator light activity, true for on, false for off
86+
func (d Drive) Indicate(active bool) error {
87+
return d.Post(d.indicateTarget(), map[string]interface{}{"Active": active})
6288
}

oem/smc/drive_test.go

+4-17
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,11 @@ func TestSmcDriveOem(t *testing.T) {
5757
t.Fatalf("error getting oem info from drive: %v", err)
5858
}
5959

60-
if smcDrive.Oem.Supermicro.Temperature != 33 {
61-
t.Errorf("unexpected oem drive temerature: %d", smcDrive.Oem.Supermicro.Temperature)
62-
}
63-
}
64-
65-
// TestSmcDriveActionOem tests the parsing of the Drive Actions field
66-
func TestSmcDriveActionOem(t *testing.T) {
67-
drive := &redfish.Drive{}
68-
if err := json.Unmarshal([]byte(smcDriveBody), drive); err != nil {
69-
t.Fatalf("error decoding json: %v", err)
70-
}
71-
72-
smcDriveActions, err := FromDriveActions(&drive.Actions)
73-
if err != nil {
74-
t.Fatalf("error getting oem info from drive: %v", err)
60+
if smcDrive.Temperature() != 33 {
61+
t.Errorf("unexpected oem drive temerature: %d", smcDrive.Temperature())
7562
}
7663

77-
if smcDriveActions.DriveIndicateTarget() != "/redfish/v1/Chassis/NVMeSSD.0.Group.0.StorageBackplane/Drives/Disk.Bay.22/Actions/Oem/Drive.Indicate" {
78-
t.Errorf("unexpected oem drive indicator target: %s", smcDriveActions.DriveIndicateTarget())
64+
if smcDrive.indicateTarget() != "/redfish/v1/Chassis/NVMeSSD.0.Group.0.StorageBackplane/Drives/Disk.Bay.22/Actions/Oem/Drive.Indicate" {
65+
t.Errorf("unexpected oem drive indicator target: %s", smcDrive.indicateTarget())
7966
}
8067
}

0 commit comments

Comments
 (0)