@@ -6,57 +6,83 @@ import (
6
6
"github.com/stmcginnis/gofish/redfish"
7
7
)
8
8
9
+ // Drive extends a redfish.Drive for additional OEM fields
9
10
type Drive struct {
10
11
redfish.Drive
11
- Oem DriveOem `json:"Oem"`
12
+ smc struct {
13
+ Oem driveOem `json:"Oem"`
14
+ Actions driveActions `json:"Actions"`
15
+ }
12
16
}
13
17
14
- type DriveOem struct {
18
+ type driveOem struct {
15
19
Supermicro struct {
16
20
Temperature int
17
21
PercentageDriveLifeUsed int
18
22
DriveFunctional bool
19
23
} `json:"Supermicro"`
20
24
}
21
25
22
- type DriveTarget struct {
26
+ type driveTarget struct {
23
27
Target string `json:"target"`
24
28
ActionInfo string `json:"@Redfish.ActionInfo"`
25
29
}
26
30
27
- type DriveActions struct {
31
+ type driveActions struct {
28
32
redfish.DriveActions
29
33
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"`
32
36
} `json:"Oem"`
33
37
}
34
38
39
+ // FromDrive returns an OEM-extended redfish drive
35
40
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 {
40
42
Drive : * drive ,
41
- Oem : oem ,
42
- }, err
43
- }
43
+ }
44
+ smcDrive .smc .Actions .DriveActions = drive .Actions
44
45
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
48
48
}
49
49
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
52
65
}
53
66
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
59
80
}
60
81
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 })
62
88
}
0 commit comments