Skip to content

Commit

Permalink
redfish/drive: expose raw data for oem support
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Vandermeulen <[email protected]>
  • Loading branch information
Matt1360 committed Oct 15, 2024
1 parent 0c6c55a commit 5db2bd6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
27 changes: 14 additions & 13 deletions redfish/drive.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,6 @@ type Drive struct {
// WriteCacheEnabled shall indicate whether the drive
// write cache is enabled.
WriteCacheEnabled bool
// Actions are all the listed actions under the drive
Actions DriveActions
// Oem is all the available OEM information for the drive
Oem json.RawMessage

Expand Down Expand Up @@ -333,14 +331,11 @@ type Drive struct {
storagePools []string
// storagePools []string
StoragePoolsCount int
// rawData holds the original serialized JSON so we can compare updates.
rawData []byte
}

// DriveActions are a set of actions available under a drive
type DriveActions struct {
SecureErase common.ActionTarget `json:"#Drive.SecureErase"`
Oem json.RawMessage
// secureEraseTarget is the URL for SecureErase actions.
secureEraseTarget string
// RawData holds the original serialized JSON so we can compare updates
// as well as access Oem values in the oem package.
RawData []byte
}

// UnmarshalJSON unmarshals a Drive object from the raw JSON.
Expand Down Expand Up @@ -372,9 +367,13 @@ func (drive *Drive) UnmarshalJSON(b []byte) error {
Volumes common.Links
VolumeCount int `json:"[email protected]"`
}
type Actions struct {
SecureErase common.ActionTarget `json:"#Drive.SecureErase"`
}
var t struct {
temp
Links links
Actions Actions
Assembly common.Link
EnvironmentMetrics common.Link
}
Expand Down Expand Up @@ -406,8 +405,10 @@ func (drive *Drive) UnmarshalJSON(b []byte) error {
drive.volumes = t.Links.Volumes.ToStrings()
drive.VolumesCount = t.Links.VolumeCount

drive.secureEraseTarget = t.Actions.SecureErase.Target

// This is a read/write object, so we need to save the raw object data for later
drive.rawData = b
drive.RawData = b

return nil
}
Expand All @@ -417,7 +418,7 @@ func (drive *Drive) Update() error {
// Get a representation of the object's original state so we can find what
// to update.
original := new(Drive)
err := original.UnmarshalJSON(drive.rawData)
err := original.UnmarshalJSON(drive.RawData)
if err != nil {
return err
}
Expand Down Expand Up @@ -489,5 +490,5 @@ func (drive *Drive) PCIeFunctions() ([]*PCIeFunction, error) {

// SecureErase shall perform a secure erase of the drive.
func (drive *Drive) SecureErase() error {
return drive.Post(drive.Actions.SecureErase.Target, nil)
return drive.Post(drive.secureEraseTarget, nil)
}
4 changes: 2 additions & 2 deletions redfish/drive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ func TestDrive(t *testing.T) {
t.Errorf("Invalid chassis link: %s", result.chassis)
}

if result.Actions.SecureErase.Target != "/redfish/v1/Chassis/NVMeChassis/Disk.Bay.0/Actions/Drive.SecureErase" {
t.Errorf("Invalid SecureErase target: %s", result.Actions.SecureErase.Target)
if result.secureEraseTarget != "/redfish/v1/Chassis/NVMeChassis/Disk.Bay.0/Actions/Drive.SecureErase" {
t.Errorf("Invalid SecureErase target: %s", result.secureEraseTarget)
}
}

Expand Down

0 comments on commit 5db2bd6

Please sign in to comment.