Skip to content

Commit

Permalink
Fix OperatingSystem link in ComputerSystem (#380)
Browse files Browse the repository at this point in the history
The OperatingSystem property was defined as a string, but this field is
actually a link to another object. This updates the definition to parse
out the link and adds an accessor method to get the actual
OperatingSystem object.

Signed-off-by: Sean McGinnis <[email protected]>
  • Loading branch information
stmcginnis authored Oct 23, 2024
1 parent 9bc001c commit 07667e4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion redfish/computersystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ type ComputerSystem struct {
OEM json.RawMessage `json:"Oem"`
// OperatingSystem shall contain a link to a resource of type OperatingSystem that contains operating system
// information for this system.
OperatingSystem string
operatingSystem string
// PCIeDevices shall be an array of references of type PCIeDevice.
pcieDevices []string
// PCIeDevicesCount is the number of PCIeDevices.
Expand Down Expand Up @@ -960,6 +960,7 @@ func (computersystem *ComputerSystem) UnmarshalJSON(b []byte) error {
Processors common.Link
Redundancy common.Link
Memory common.Link
OperatingSystem common.Link
SimpleStorage common.Link
SecureBoot common.Link
Storage common.Link
Expand Down Expand Up @@ -994,6 +995,7 @@ func (computersystem *ComputerSystem) UnmarshalJSON(b []byte) error {
computersystem.memory = t.Memory.String()
computersystem.memoryDomains = t.MemoryDomains.String()
computersystem.networkInterfaces = t.NetworkInterfaces.String()
computersystem.operatingSystem = t.OperatingSystem.String()
computersystem.redundancy = t.Redundancy.String()
computersystem.secureBoot = t.SecureBoot.String()
computersystem.simpleStorage = t.SimpleStorage.String()
Expand Down Expand Up @@ -1114,6 +1116,11 @@ func (computersystem *ComputerSystem) NetworkInterfaces() ([]*NetworkInterface,
return ListReferencedNetworkInterfaces(computersystem.GetClient(), computersystem.networkInterfaces)
}

// OperatingSystem gets this system's operating system.
func (computersystem *ComputerSystem) OperatingSystem() (*OperatingSystem, error) {
return GetOperatingSystem(computersystem.GetClient(), computersystem.operatingSystem)
}

// PCIeDevices gets all PCIeDevices for this system.
func (computersystem *ComputerSystem) PCIeDevices() ([]*PCIeDevice, error) {
return common.GetObjects[PCIeDevice](computersystem.GetClient(), computersystem.pcieDevices)
Expand Down
7 changes: 7 additions & 0 deletions redfish/computersystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ var computerSystemBody = `{
"Storage": {
"@odata.id": "/redfish/v1/Systems/1/Storage"
},
"OperatingSystem": {
"@odata.id": "/redfish/v1/Systems/1/OperatingSystem"
},
"LogServices": {
"@odata.id": "/redfish/v1/Systems/1/LogServices"
},
Expand Down Expand Up @@ -310,6 +313,10 @@ func TestComputerSystem(t *testing.T) { //nolint
if result.managedBy[0] != "/redfish/v1/Managers/BMC-1" {
t.Errorf("Received invalid Managers reference: %s", result.managedBy[0])
}

if result.operatingSystem != "/redfish/v1/Systems/1/OperatingSystem" {
t.Errorf("Received invalid OperatingSystem reference: %s", result.operatingSystem)
}
}

// TestComputerSystemUpdate tests the Update call.
Expand Down

0 comments on commit 07667e4

Please sign in to comment.