Skip to content

Commit 73b8a2d

Browse files
committed
Add some AMI OEM objects
This is far from complete, but adds some basic OEM objects for AMI-based Redfish implementations. Signed-off-by: Sean McGinnis <[email protected]>
1 parent aa597ec commit 73b8a2d

10 files changed

+959
-2
lines changed

oem/ami/accountservice.go

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
//
2+
// SPDX-License-Identifier: BSD-3-Clause
3+
//
4+
5+
package ami
6+
7+
import (
8+
"encoding/json"
9+
10+
"github.com/stmcginnis/gofish/common"
11+
"github.com/stmcginnis/gofish/redfish"
12+
)
13+
14+
// PAMOrder is the PAM modules used for authentication.
15+
type PAMOrder string
16+
17+
const (
18+
// IPMIPAMOrder specifies IPMI authentication.
19+
IPMIPAMOrder PAMOrder = "IPMI"
20+
// LDAPPAMOrder specifies LDAP authentication.
21+
LDAPPAMOrder PAMOrder = "LDAP"
22+
// ACTIVEDIRECTORYPAMOrder specifies ACTIVE DIRECTORY authentication.
23+
ACTIVEDIRECTORYPAMOrder PAMOrder = "ACTIVE DIRECTORY"
24+
// RADIUSPAMOrder specifies RADIUS authentication.
25+
RADIUSPAMOrder PAMOrder = "RADIUS"
26+
)
27+
28+
// AccountServiceConfigurations allows additional configuring of the AMI AccountService.
29+
type AccountServiceConfigurations struct {
30+
common.Entity
31+
// ODataContext is the odata context.
32+
ODataContext string `json:"@odata.context"`
33+
// ODataEtag is the odata etag.
34+
ODataEtag string `json:"@odata.etag"`
35+
// ODataType is the odata type.
36+
ODataType string `json:"@odata.type"`
37+
// Description provides a description of this resource.
38+
Description string
39+
// PAMEnabled indicates whether or not PAM authentication should be used when authenticating Redfish requests.
40+
PAMEnabled bool
41+
// PAMOrder is an array that represents the order the PAM modules will be checked for authentication.
42+
PAMOrder []PAMOrder
43+
}
44+
45+
// GetAccountServiceConfigurations will get an AccountServiceConfigurations instance from the Redfish
46+
// service.
47+
func GetAccountServiceConfigurations(c common.Client, uri string) (*AccountServiceConfigurations, error) {
48+
return common.GetObject[AccountServiceConfigurations](c, uri)
49+
}
50+
51+
// AccountService is an AMI OEM instance of an AccountService.
52+
type AccountService struct {
53+
redfish.AccountService
54+
55+
configuration string
56+
}
57+
58+
// FromAccountService converts a standard AccountService object to the OEM implementation.
59+
func FromAccountService(accountService *redfish.AccountService) (*AccountService, error) {
60+
as := AccountService{
61+
AccountService: *accountService,
62+
}
63+
64+
var t struct {
65+
Oem struct {
66+
AMI struct {
67+
Configurtion common.Link `json:"Configuration"`
68+
} `json:"AMI"`
69+
} `json:"Oem"`
70+
}
71+
72+
err := json.Unmarshal(accountService.RawData, &t)
73+
if err != nil {
74+
return nil, err
75+
}
76+
77+
as.configuration = t.Oem.AMI.Configurtion.String()
78+
as.SetClient(accountService.GetClient())
79+
80+
return &as, nil
81+
}
82+
83+
// Configuration will get the AccountServiceConfigurations for this AccountService.
84+
func (as *AccountService) Configuration() (*AccountServiceConfigurations, error) {
85+
return GetAccountServiceConfigurations(as.GetClient(), as.configuration)
86+
}

oem/ami/accountservice_test.go

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
//
2+
// SPDX-License-Identifier: BSD-3-Clause
3+
//
4+
5+
package ami
6+
7+
import (
8+
"encoding/json"
9+
"strings"
10+
"testing"
11+
12+
"github.com/stmcginnis/gofish/redfish"
13+
)
14+
15+
var accountServiceBody = `{
16+
"@odata.type": "#AccountService.v1_7_2.AccountService",
17+
"@odata.id": "/redfish/v1/AccountService",
18+
"Id": "AccountService",
19+
"Name": "Account Service",
20+
"Oem": {
21+
"Ami": {
22+
"@odata.type": "#AMIAccountService.v1_0_0.AMIAccountService",
23+
"Configuration": {
24+
"@odata.id": "/redfish/v1/AccountService/Oem/Ami/Configurations"
25+
}
26+
}
27+
},
28+
"PrivilegeMap": {
29+
"@odata.id": "/redfish/v1/Registries/Redfish_1.4.0_PrivilegeRegistry.json"
30+
},
31+
"Roles": {
32+
"@odata.id": "/redfish/v1/AccountService/Roles"
33+
},
34+
"ServiceEnabled": true,
35+
"Status": {
36+
"Health": "OK",
37+
"State": "Enabled"
38+
}
39+
}`
40+
41+
// TestAMIAccountService tests the parsing of the AccountService.
42+
func TestAMIAccountService(t *testing.T) {
43+
as := &redfish.AccountService{}
44+
if err := json.Unmarshal([]byte(accountServiceBody), as); err != nil {
45+
t.Fatalf("error decoding json: %v", err)
46+
}
47+
48+
accountService, err := FromAccountService(as)
49+
if err != nil {
50+
t.Fatalf("error getting oem info: %v", err)
51+
}
52+
53+
if accountService.ID != "AccountService" {
54+
t.Errorf("unexpected ID: %s", accountService.ID)
55+
}
56+
57+
if accountService.configuration != "/redfish/v1/AccountService/Oem/Ami/Configurations" {
58+
t.Errorf("unexpected configuration link: %s", accountService.configuration)
59+
}
60+
}
61+
62+
var accountServiceConfigurationsBody = `{
63+
"@odata.context": "/redfish/v1/$metadata#AMIAccountServiceConfigurations.AMIAccountServiceConfigurations",
64+
"@odata.etag": "\"1729105654\"",
65+
"@odata.id": "/redfish/v1/AccountService/Oem/Ami/Configurations",
66+
"@odata.type": "#AMIAccountServiceConfigurations.v1_0_0.AMIAccountServiceConfigurations",
67+
"Id": "Configurations",
68+
"Name": "AccountService Configurations",
69+
"PAMEnabled": true,
70+
"PAMOrder": [
71+
"IPMI",
72+
"LDAP",
73+
"ACTIVE DIRECTORY",
74+
"RADIUS"
75+
]
76+
}`
77+
78+
// TestAMIAccountServiceConfigurations tests the parsing of the AccountServiceConfigurations.
79+
func TestAMIAccountServiceConfigurations(t *testing.T) {
80+
var result AccountServiceConfigurations
81+
err := json.NewDecoder(strings.NewReader(accountServiceConfigurationsBody)).Decode(&result)
82+
83+
if err != nil {
84+
t.Errorf("Error decoding JSON: %s", err)
85+
}
86+
87+
if result.ID != "Configurations" {
88+
t.Errorf("unexpected ID: %s", result.ID)
89+
}
90+
91+
if !result.PAMEnabled {
92+
t.Errorf("unexpected PAMEnabled: %t", result.PAMEnabled)
93+
}
94+
95+
if len(result.PAMOrder) != 4 {
96+
t.Errorf("unexpected PAMOrder length: %d", len(result.PAMOrder))
97+
}
98+
99+
if result.PAMOrder[0] != "IPMI" {
100+
t.Errorf("unexpected PAMOrder[0]: %s", result.PAMOrder[0])
101+
}
102+
}

oem/ami/computersystem.go

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
//
2+
// SPDX-License-Identifier: BSD-3-Clause
3+
//
4+
5+
package ami
6+
7+
import (
8+
"encoding/json"
9+
10+
"github.com/stmcginnis/gofish/common"
11+
"github.com/stmcginnis/gofish/redfish"
12+
)
13+
14+
// ManagerBootMode is is the boot mode of the manager.
15+
type ManagerBootMode string
16+
17+
const (
18+
// NoneManagerBootMode Added None in Boot Option
19+
NoneManagerBootMode ManagerBootMode = "None"
20+
// SoftResetManagerBootMode Added SoftReset in Boot Option
21+
SoftResetManagerBootMode ManagerBootMode = "SoftReset"
22+
// ResetTimeoutManagerBootMode ResetTimeout support is Boot Option
23+
ResetTimeoutManagerBootMode ManagerBootMode = "ResetTimeout"
24+
)
25+
26+
// AMIBIOSInventoryCRC provides the information related to inventory data/
27+
//
28+
//nolint:revive
29+
type AMIBIOSInventoryCRC struct {
30+
// Bios provides the information related to inventory data.
31+
Bios Bios
32+
// ManagerBootConfiguration indicates the properties related to ManagerBoot
33+
ManagerBootConfiguration ManagerBootConfiguration
34+
}
35+
36+
// BiosTableis the root for BiosTable information.
37+
type BiosTable struct {
38+
common.Entity
39+
// ODataContext is the odata context.
40+
ODataContext string `json:"@odata.context"`
41+
// ODataType is the odata type.
42+
ODataType string `json:"@odata.type"`
43+
// Description provides a description of this resource.
44+
Description string
45+
// FilesContent contains the contents of the BiosTable file.
46+
FilesContent string
47+
}
48+
49+
// TableTag contains the TableTag informations.
50+
type TableTag struct {
51+
// TableType shall contain a string representing the TableTag.
52+
TableType string
53+
// Value shall contains the value for the corresponding TableTag.
54+
Value string
55+
}
56+
57+
// BiosTableTags is the root for TableTags information.
58+
type BiosTableTags struct {
59+
common.Entity
60+
// ODataContext is the odata context.
61+
ODataContext string `json:"@odata.context"`
62+
// ODataType is the odata type.
63+
ODataType string `json:"@odata.type"`
64+
// Description provides a description of this resource.
65+
Description string
66+
// NumberofTables contains the number of TableTags present.
67+
NumberofTables string
68+
// TableTags contains the TableTags informations.
69+
TableTags []TableTag
70+
}
71+
72+
// Bios
73+
type Bios struct {
74+
// BiosTable provides the information related to BiosTable
75+
BiosTable BiosTable
76+
// BiosTableTags provides the information related to BiosTableTags.
77+
BiosTableTags BiosTableTags
78+
// Inventory provides the information related to inventory data Crc value.
79+
Inventory Inventory
80+
// RedfishVersion shall represent the version of the Redfish service. The format of this string shall be of the
81+
// format majorversion.minorversion.errata in compliance with Protocol Version section of the Redfish
82+
// specification.
83+
RedfishVersion string
84+
// RTPVersion shall represent the version of the RTP Version.
85+
RTPVersion string
86+
}
87+
88+
// Crc
89+
type Crc struct {
90+
// GroupCrcList provides the information related to inventory data of GroupCrcList value.
91+
GroupCrcList []map[string]uint64
92+
}
93+
94+
// Inventory
95+
type Inventory struct {
96+
// Crc provides the information related to inventory data of Crc value.
97+
Crc Crc
98+
}
99+
100+
// ManagerBootConfiguration
101+
type ManagerBootConfiguration struct {
102+
// ManagerBootMode shall specify the enum supported by ManagerBootMode.
103+
ManagerBootMode ManagerBootMode
104+
}
105+
106+
// ComputerSystem is the update service instance associated with the system.
107+
type ComputerSystem struct {
108+
redfish.ComputerSystem
109+
110+
BIOS Bios
111+
ManagerBootConfiguration ManagerBootConfiguration
112+
SSIFMode string
113+
}
114+
115+
// FromComputerSystem gets the OEM instance of the ComputerSystemSystem.
116+
func FromComputerSystem(computerSystem *redfish.ComputerSystem) (*ComputerSystem, error) {
117+
us := ComputerSystem{
118+
ComputerSystem: *computerSystem,
119+
}
120+
121+
var t struct {
122+
Oem struct {
123+
Ami struct {
124+
BIOS Bios `json:"BIOS"`
125+
ManagerBootConfiguration ManagerBootConfiguration `json:"ManagerBootConfiguration"`
126+
SSIFMode string `json:"SSIFMode"`
127+
}
128+
}
129+
}
130+
131+
err := json.Unmarshal(computerSystem.RawData, &t)
132+
if err != nil {
133+
return nil, err
134+
}
135+
136+
us.BIOS = t.Oem.Ami.BIOS
137+
us.ManagerBootConfiguration = t.Oem.Ami.ManagerBootConfiguration
138+
us.SSIFMode = t.Oem.Ami.SSIFMode
139+
140+
return &us, nil
141+
}

0 commit comments

Comments
 (0)