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

Add Supermicro OEM ComputerSystem objects #367

Merged
merged 1 commit into from
Oct 14, 2024
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
56 changes: 56 additions & 0 deletions oem/smc/computersystem.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// SPDX-License-Identifier: BSD-3-Clause
//

package smc

import (
"encoding/json"

"github.com/stmcginnis/gofish/common"
"github.com/stmcginnis/gofish/redfish"
)

// ComputerSystem is a Supermicro OEM instance of a ComputerSystem.
type ComputerSystem struct {
redfish.ComputerSystem
nodeManager string
fixedBootOrder string
}

// NodeManager gets the NodeManager for the system.
func (cs *ComputerSystem) NodeManager() (*NodeManager, error) {
return GetNodeManager(cs.GetClient(), cs.nodeManager)
}

// FixedBootOrder gets the FixedBootOrder instance for the system.
func (cs *ComputerSystem) FixedBootOrder() (*FixedBootOrder, error) {
return GetFixedBootOrder(cs.GetClient(), cs.fixedBootOrder)
}

// FromComputerSystem converts a standard ComputerSystem object to the OEM implementation.
func FromComputerSystem(system *redfish.ComputerSystem) (*ComputerSystem, error) {
type Oem struct {
Supermicro struct {
NodeManager common.Link `json:"NodeManager"`
FixedBootOrder common.Link `json:"FixedBootOrder"`
} `json:"Supermicro"`
}

cs := &ComputerSystem{}
err := json.Unmarshal(system.RawData, cs)
if err != nil {
return nil, err
}

oem := &Oem{}
err = json.Unmarshal(cs.OEM, oem)
if err != nil {
return nil, err
}
cs.nodeManager = oem.Supermicro.NodeManager.String()
cs.fixedBootOrder = oem.Supermicro.FixedBootOrder.String()

cs.SetClient(system.GetClient())
return cs, nil
}
222 changes: 222 additions & 0 deletions oem/smc/computersystem_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
//
// SPDX-License-Identifier: BSD-3-Clause
//

package smc

import (
"encoding/json"
"strings"
"testing"

"github.com/stmcginnis/gofish/redfish"
)

var computerSystemBody = `{
"@odata.type": "#ComputerSystem.v1_14_0.ComputerSystem",
"@odata.id": "/redfish/v1/Systems/1",
"Id": "1",
"Name": "System",
"Description": "Description of server",
"Status": {
"State": "Enabled",
"Health": "OK"
},
"SerialNumber": "S514359X4916804",
"PartNumber": "SYS-821GE-200-02-LL014",
"IndicatorLED": "Off",
"LocationIndicatorActive": false,
"SystemType": "Physical",
"BiosVersion": "2.1",
"Manufacturer": "Supermicro",
"Model": "SYS-821GE-TNHR",
"SKU": "0x1D1415D9",
"UUID": "D4216600-C32C-11EE-8000-7CC25586E492",
"ProcessorSummary": {
"Count": 2,
"Model": "Intel(R) Xeon(R) processor",
"Status": {
"State": "Enabled",
"Health": "OK",
"HealthRollup": "OK"
},
"Metrics": {
"@odata.id": "/redfish/v1/Systems/1/ProcessorSummary/ProcessorMetrics"
}
},
"MemorySummary": {
"TotalSystemMemoryGiB": 2048,
"MemoryMirroring": "System",
"Status": {
"State": "Enabled",
"Health": "OK",
"HealthRollup": "OK"
},
"Metrics": {
"@odata.id": "/redfish/v1/Systems/1/MemorySummary/MemoryMetrics"
}
},
"PowerState": "On",
"PowerOnDelaySeconds": 3,
"[email protected]": [
"3:254:1"
],
"PowerOffDelaySeconds": 3,
"[email protected]": [
"3:254:1"
],
"PowerCycleDelaySeconds": 5,
"[email protected]": [
"5:254:1"
],
"Boot": {
"BootSourceOverrideEnabled": "Disabled",
"BootSourceOverrideMode": "UEFI",
"BootSourceOverrideTarget": "Pxe",
"[email protected]": [
"None",
"Pxe",
"Floppy",
"Cd",
"Usb",
"Hdd",
"BiosSetup",
"UsbCd",
"UefiBootNext",
"UefiHttp"
],
"BootOptions": {
"@odata.id": "/redfish/v1/Systems/1/BootOptions"
},
"BootNext": null,
"BootOrder": [
"Boot0003",
"Boot0004",
"Boot0005",
"Boot0006",
"Boot0002",
"Boot0001"
]
},
"GraphicalConsole": {
"ServiceEnabled": true,
"Port": 5900,
"MaxConcurrentSessions": 4,
"ConnectTypesSupported": [
"KVMIP"
]
},
"SerialConsole": {
"MaxConcurrentSessions": 1,
"SSH": {
"ServiceEnabled": true,
"Port": 22,
"SharedWithManagerCLI": true,
"ConsoleEntryCommand": "cd system1/sol1; start",
"HotKeySequenceDisplay": "press <Enter>, <Esc>, and then <T> to terminate session"
},
"IPMI": {
"HotKeySequenceDisplay": "Press ~. - terminate connection",
"ServiceEnabled": true,
"Port": 623
}
},
"VirtualMediaConfig": {
"ServiceEnabled": true,
"Port": 623
},
"BootProgress": {
"LastState": "SystemHardwareInitializationComplete"
},
"Processors": {
"@odata.id": "/redfish/v1/Systems/1/Processors"
},
"Memory": {
"@odata.id": "/redfish/v1/Systems/1/Memory"
},
"EthernetInterfaces": {
"@odata.id": "/redfish/v1/Systems/1/EthernetInterfaces"
},
"NetworkInterfaces": {
"@odata.id": "/redfish/v1/Systems/1/NetworkInterfaces"
},
"SimpleStorage": {
"@odata.id": "/redfish/v1/Systems/1/SimpleStorage"
},
"Storage": {
"@odata.id": "/redfish/v1/Systems/1/Storage"
},
"LogServices": {
"@odata.id": "/redfish/v1/Systems/1/LogServices"
},
"SecureBoot": {
"@odata.id": "/redfish/v1/Systems/1/SecureBoot"
},
"Bios": {
"@odata.id": "/redfish/v1/Systems/1/Bios"
},
"VirtualMedia": {
"@odata.id": "/redfish/v1/Managers/1/VirtualMedia"
},
"Links": {
"Chassis": [
{
"@odata.id": "/redfish/v1/Chassis/1"
}
],
"ManagedBy": [
{
"@odata.id": "/redfish/v1/Managers/1"
}
]
},
"Actions": {
"Oem": {},
"#ComputerSystem.Reset": {
"target": "/redfish/v1/Systems/1/Actions/ComputerSystem.Reset",
"@Redfish.ActionInfo": "/redfish/v1/Systems/1/ResetActionInfo"
}
},
"Oem": {
"Supermicro": {
"NodeManager": {
"@odata.id": "/redfish/v1/Systems/1/Oem/Supermicro/NodeManager"
},
"FixedBootOrder": {
"@odata.id": "/redfish/v1/Systems/1/Oem/Supermicro/FixedBootOrder"
},
"@odata.type": "#SmcSystemExtensions.v1_0_0.System"
}
},
"@odata.etag": "\"36f059d60095337115952f02709f65d6\""
}`

// TestComputerSystem tests the parsing of ComputerSystem objects.
func TestComputerSystem(t *testing.T) {
var cs redfish.ComputerSystem
err := json.NewDecoder(strings.NewReader(computerSystemBody)).Decode(&cs)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}

result, err := FromComputerSystem(&cs)
if err != nil {
t.Errorf("Error converting Redfish ComputerSystem to SMC ComputerSystem: %s", err)
}

if result.ID != "1" {
t.Errorf("Received invalid ID: %s", result.ID)
}

if result.Name != "System" {
t.Errorf("Received invalid name: %s", result.Name)
}

if result.nodeManager != "/redfish/v1/Systems/1/Oem/Supermicro/NodeManager" {
t.Errorf("Invalid node manager link: %s", result.nodeManager)
}

if result.fixedBootOrder != "/redfish/v1/Systems/1/Oem/Supermicro/FixedBootOrder" {
t.Errorf("Invalid fixed boot order link: %s", result.fixedBootOrder)
}
}
31 changes: 31 additions & 0 deletions oem/smc/fixedbootorder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// SPDX-License-Identifier: BSD-3-Clause
//

package smc

import (
"github.com/stmcginnis/gofish/common"
)

// FixedBootOrder is the fixed boot order information associated with the system.
// The non-OEM ComputerSystem BootOrder property does not support PATCH method
// since X13/H13 platforms Configuring system boot device order should be via
// FixedBootOrder.
// TODO: This is currently read-only in Gofish.
type FixedBootOrder struct {
common.Entity
BootModeSelected string
FixedBootOrder []string
FixedBootOrderDisabledItem []string
UEFINetwork []string
UEFINetworkDisabledItem []string
UEFIHardDisk []string
UEFIAP []string
UEFIAPDisabledItem []string
}

// GetFixedBootOrder will get a FixedBootOrder instance from the service.
func GetFixedBootOrder(c common.Client, uri string) (*FixedBootOrder, error) {
return common.GetObject[FixedBootOrder](c, uri)
}
76 changes: 76 additions & 0 deletions oem/smc/fixedbootorder_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//
// SPDX-License-Identifier: BSD-3-Clause
//

package smc

import (
"encoding/json"
"strings"
"testing"
)

var fixedBootOrderBody = `{
"@odata.type": "#SmcFixedBootOrder.v1_0_0.SmcFixedBootOrder",
"@odata.id": "/redfish/v1/Systems/1/Oem/Supermicro/FixedBootOrder",
"Id": "FixedBootOrder",
"Name": "Fixed Boot Order",
"BootModeSelected": "UEFI",
"FixedBootOrder": [
"UEFI CD/DVD",
"UEFI USB CD/DVD",
"UEFI Network:(B83/D0/F0) UEFI PXE IPv4 Intel(R) Ethernet Controller X550 - 905A0839F618",
"UEFI Hard Disk:ubuntu (HDD,Port:900)",
"UEFI USB Hard Disk",
"UEFI USB Key",
"UEFI USB Floppy",
"UEFI USB Lan",
"UEFI AP:UEFI: Built-in EFI Shell"
],
"FixedBootOrderDisabledItem": [
"Disabled"
],
"UEFINetwork": [
"(B83/D0/F0) UEFI PXE IPv4 Intel(R) Ethernet Controller X550 - 905A0839F618",
"(B83/D0/F1) UEFI PXE IPv4 Intel(R) Ethernet Controller X550 - 905A0839F619",
"(B210/D0/F0) UEFI PXE IPv4 Nvidia Network Adapter - 5C:25:73:60:C5:D8 - 5C257360C5D8",
"(B210/D0/F1) UEFI PXE IPv4 Nvidia Network Adapter - 5C:25:73:60:C5:D9 - 5C257360C5D9"
],
"UEFINetworkDisabledItem": [
"Disabled"
],
"UEFIHardDisk": [
"ubuntu (HDD,Port:900)"
],
"UEFIHardDiskDisabledItem": [
"Disabled"
],
"UEFIAP": [
"UEFI: Built-in EFI Shell"
],
"UEFIAPDisabledItem": [
"Disabled"
],
"@odata.etag": "\"120671877241e67076141a0d63fc7c7b\""
}`

// TestFixedBootOrder tests the parsing of FixedBootOrder objects.
func TestFixedBootOrder(t *testing.T) {
var result FixedBootOrder
err := json.NewDecoder(strings.NewReader(fixedBootOrderBody)).Decode(&result)
if err != nil {
t.Errorf("Error decoding JSON: %s", err)
}

if result.ID != "FixedBootOrder" {
t.Errorf("Received invalid ID: %s", result.ID)
}

if result.BootModeSelected != "UEFI" {
t.Errorf("Invalid BootModeSelected: %s", result.BootModeSelected)
}

if len(result.FixedBootOrder) != 9 {
t.Errorf("Expected 9 fixed boot order entries, got %d", len(result.FixedBootOrder))
}
}
Loading