From 6919e15c6e138322c2634eb88d83062b1e548bc8 Mon Sep 17 00:00:00 2001 From: Dmitrii Okunev Date: Fri, 8 Oct 2021 14:33:26 +0100 Subject: [PATCH] feat(redfish/bios): Add GetActiveSoftwareImage (#158) 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 --- redfish/bios.go | 20 ++++++++++++++++++++ redfish/bios_test.go | 9 +++++++++ 2 files changed, 29 insertions(+) diff --git a/redfish/bios.go b/redfish/bios.go index a284e095..e25def3c 100644 --- a/redfish/bios.go +++ b/redfish/bios.go @@ -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 } @@ -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"` } @@ -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. @@ -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) +} diff --git a/redfish/bios_test.go b/redfish/bios_test.go index c787ad7b..d90ad9e1 100644 --- a/redfish/bios_test.go +++ b/redfish/bios_test.go @@ -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" + } } }` @@ -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.