Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redfish/drive: expose oem data and actions #366

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions redfish/drive.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ 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

// ActiveSoftwareImage shall contain a link a resource of type SoftwareInventory that represents the active drive
// firmware image.
Expand Down Expand Up @@ -329,12 +333,16 @@ type Drive struct {
storagePools []string
// storagePools []string
StoragePoolsCount int
// secureEraseTarget is the URL for SecureErase actions.
secureEraseTarget string
// 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
}

// UnmarshalJSON unmarshals a Drive object from the raw JSON.
func (drive *Drive) UnmarshalJSON(b []byte) error {
type temp Drive
Expand Down Expand Up @@ -364,13 +372,9 @@ 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 All @@ -391,6 +395,7 @@ func (drive *Drive) UnmarshalJSON(b []byte) error {
drive.EndpointsCount = t.Links.EndpointCount
drive.networkDeviceFunctions = t.Links.NetworkDeviceFunctions.ToStrings()
drive.NetworkDeviceFunctionsCount = t.Links.NetworkDeviceFunctionsCount
drive.Oem = t.Oem
drive.pcieFunctions = t.Links.PCIeFunctions.ToStrings()
drive.PCIeFunctionCount = t.Links.PCIeFunctionsCount
drive.softwareImages = t.Links.SoftwareImages.ToStrings()
Expand All @@ -401,8 +406,6 @@ 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

Expand Down Expand Up @@ -486,5 +489,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.secureEraseTarget, nil)
return drive.Post(drive.Actions.SecureErase.Target, 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.secureEraseTarget != "/redfish/v1/Chassis/NVMeChassis/Disk.Bay.0/Actions/Drive.SecureErase" {
t.Errorf("Invalid SecureErase target: %s", result.secureEraseTarget)
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)
}
}

Expand Down