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

feat(redfish/bios): Add GetActiveSoftwareImage #158

Merged
Show file tree
Hide file tree
Changes from all commits
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
20 changes: 20 additions & 0 deletions redfish/bios.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 84,9 @@ type Bios struct {
// settingsApplyTimes is a set of allowed settings update apply times. If none
// are specified, then the system does not provide that information.
settingsApplyTimes []common.ApplyTime
// activeSoftwareImage is the @odata.id of SoftwareInventory responsible
// for the active BIOS firmware image (see [email protected]).
activeSoftwareImage string
// rawData holds the original serialized JSON so we can compare updates.
rawData []byte
}
Expand All @@ -99,9 102,15 @@ func (bios *Bios) UnmarshalJSON(b []byte) error {
Target string
} `json:"#Bios.ResetBios"`
}
type Links struct {
ActiveSoftwareImage struct {
ODataID string `json:"@odata.id"`
}
}
var t struct {
temp
Actions Actions
Links Links
Settings common.Settings `json:"@Redfish.Settings"`
}

Expand All @@ -116,6 125,7 @@ func (bios *Bios) UnmarshalJSON(b []byte) error {
bios.changePasswordTarget = t.Actions.ChangePassword.Target
bios.resetBiosTarget = t.Actions.ResetBios.Target
bios.settingsApplyTimes = t.Settings.SupportedApplyTimes
bios.activeSoftwareImage = t.Links.ActiveSoftwareImage.ODataID

// Some implementations use a @Redfish.Settings object to direct settings updates to a
// different URL than the object being updated. Others don't, so handle both.
Expand Down Expand Up @@ -257,3 267,13 @@ func (bios *Bios) UpdateBiosAttributes(attrs BiosAttributes) error {

return nil
}

// GetActiveSoftwareImage gets the SoftwareInventory which represents the
// active BIOS firmware image.
func (bios *Bios) GetActiveSoftwareImage() (*SoftwareInventory, error) {
if bios.activeSoftwareImage == "" {
return nil, nil
}

return GetSoftwareInventory(bios.Client, bios.activeSoftwareImage)
}
9 changes: 9 additions & 0 deletions redfish/bios_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 54,11 @@ var biosBody = `{
"#Bios.ChangePassword": {
"target": "/redfish/v1/Systems/437XR1138R2/BIOS/Actions/Bios.ChangePassword"
}
},
"Links": {
"ActiveSoftwareImage": {
"@odata.id": "/redfish/v1/Systems/437XR1138R2/BIOS/FirmwareInventory"
}
}
}`

Expand Down Expand Up @@ -146,6 151,10 @@ func TestBios(t *testing.T) {
if len(result.settingsApplyTimes) != 3 {
t.Errorf("Invalid settings support apply times: %s", result.settingsApplyTimes)
}

if result.activeSoftwareImage != "/redfish/v1/Systems/437XR1138R2/BIOS/FirmwareInventory" {
t.Errorf("Invalid value of activeSoftwareImage: '%s'", result.activeSoftwareImage)
}
}

// TestBiosAttributes tests the parsing of Bios objects @Redfish.Attributes.
Expand Down