Skip to content

Commit

Permalink
feat(redfish/bios): Add GetActiveSoftwareImage (#158)
Browse files Browse the repository at this point in the history
Specification "Redfish Resource and Schema Guide" defines
field "Links" in Bios.v1.1+, which contains "ActiveSoftwareImage".
See: https://www.dmtf.org/sites/default/files/standards/documents/DSP2046_2020.3.pdf

Adding support of the field.

Signed-off-by: Dmitrii Okunev <xaionaro@fb.com>
  • Loading branch information
xaionaro authored Oct 8, 2021
1 parent 0c33abf commit 6919e15
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
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 Links.ActiveSoftwareImage.@odata.id).
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

0 comments on commit 6919e15

Please sign in to comment.