Skip to content

Commit 0c4da08

Browse files
committed
Refactoring after gofish version bump
1 parent f4c46c2 commit 0c4da08

6 files changed

Lines changed: 108 additions & 112 deletions

File tree

bmc/bmc.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"context"
88
"encoding/json"
99

10-
"github.com/stmcginnis/gofish"
1110
"github.com/stmcginnis/gofish/schemas"
1211
"k8s.io/apimachinery/pkg/api/resource"
1312
)

bmc/oem_helpers.go

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,28 @@ import (
1414
"slices"
1515
"strings"
1616

17-
"github.com/stmcginnis/gofish/common"
18-
"github.com/stmcginnis/gofish/redfish"
17+
"github.com/stmcginnis/gofish/schemas"
1918
ctrl "sigs.k8s.io/controller-runtime"
2019
)
2120

2221
// SimpleUpdateRequestBody extends SimpleUpdateParameters with an OEM apply-time field.
2322
type SimpleUpdateRequestBody struct {
24-
redfish.SimpleUpdateParameters
25-
RedfishOperationApplyTime redfish.OperationApplyTime `json:"@Redfish.OperationApplyTime,omitempty"`
23+
schemas.UpdateServiceSimpleUpdateParameters
24+
RedfishOperationApplyTime schemas.OperationApplyTime `json:"@Redfish.OperationApplyTime,omitempty"`
2625
}
2726

2827
// upgradeRequestBodyFn builds a vendor-specific request body from update parameters.
29-
type upgradeRequestBodyFn func(parameters *redfish.SimpleUpdateParameters) *SimpleUpdateRequestBody
28+
type upgradeRequestBodyFn func(parameters *schemas.UpdateServiceSimpleUpdateParameters) *SimpleUpdateRequestBody
3029

3130
// upgradeTaskMonitorURIFn extracts the task monitor URI from the update response.
3231
type upgradeTaskMonitorURIFn func(response *http.Response) (string, error)
3332

3433
// taskMonitorDetailsFn parses vendor-specific task monitor details.
35-
type taskMonitorDetailsFn func(ctx context.Context, response *http.Response) (*redfish.Task, error)
34+
type taskMonitorDetailsFn func(ctx context.Context, response *http.Response) (*schemas.Task, error)
3635

3736
// upgradeVersion is the common firmware upgrade flow shared by all vendors.
3837
// Vendor-specific parts are injected via callbacks.
39-
func upgradeVersion(ctx context.Context, base *RedfishBaseBMC, params *redfish.SimpleUpdateParameters, requestBodyFn upgradeRequestBodyFn, taskMonitorURIFn upgradeTaskMonitorURIFn) (string, bool, error) {
38+
func upgradeVersion(ctx context.Context, base *RedfishBaseBMC, params *schemas.UpdateServiceSimpleUpdateParameters, requestBodyFn upgradeRequestBodyFn, taskMonitorURIFn upgradeTaskMonitorURIFn) (string, bool, error) {
4039
log := ctrl.LoggerFrom(ctx)
4140
service := base.client.GetService()
4241

@@ -50,7 +49,7 @@ func upgradeVersion(ctx context.Context, base *RedfishBaseBMC, params *redfish.S
5049
AllowableValues []string `json:"TransferProtocol@Redfish.AllowableValues"`
5150
Target string
5251
} `json:"#UpdateService.SimpleUpdate"`
53-
StartUpdate common.ActionTarget `json:"#UpdateService.StartUpdate"`
52+
StartUpdate schemas.ActionTarget `json:"#UpdateService.StartUpdate"`
5453
}
5554

5655
var tUS struct {
@@ -98,7 +97,7 @@ func upgradeVersion(ctx context.Context, base *RedfishBaseBMC, params *redfish.S
9897
}
9998

10099
// getUpgradeTask is the common task polling flow shared by all vendors.
101-
func getUpgradeTask(ctx context.Context, base *RedfishBaseBMC, taskURI string, parseTaskDetails taskMonitorDetailsFn) (*redfish.Task, error) {
100+
func getUpgradeTask(ctx context.Context, base *RedfishBaseBMC, taskURI string, parseTaskDetails taskMonitorDetailsFn) (*schemas.Task, error) {
102101
log := ctrl.LoggerFrom(ctx)
103102

104103
respTask, err := base.client.GetService().GetClient().Get(taskURI)
@@ -128,11 +127,11 @@ func getUpgradeTask(ctx context.Context, base *RedfishBaseBMC, taskURI string, p
128127

129128
// httpBasedGetBMCSettingAttribute retrieves BMC settings via HTTP GET.
130129
// Shared by HPE and Lenovo which use "GET <URI>" format attributes.
131-
func httpBasedGetBMCSettingAttribute(c common.Client, attributes map[string]string) (redfish.SettingsAttributes, error) {
130+
func httpBasedGetBMCSettingAttribute(c schemas.Client, attributes map[string]string) (schemas.SettingsAttributes, error) {
132131
if c == nil {
133132
return nil, fmt.Errorf("failed to get client from gofish service")
134133
}
135-
result := redfish.SettingsAttributes{}
134+
result := schemas.SettingsAttributes{}
136135
var errs []error
137136
for key, data := range attributes {
138137
parts := strings.Fields(key)
@@ -179,8 +178,8 @@ func httpBasedGetBMCSettingAttribute(c common.Client, attributes map[string]stri
179178

180179
// httpBasedUpdateBMCAttributes applies BMC attributes via HTTP POST/PATCH.
181180
// Shared by HPE and Lenovo which use "POST <URI>" or "PATCH <URI>" format attributes.
182-
func httpBasedUpdateBMCAttributes(c common.Client, attrs redfish.SettingsAttributes, applyTime common.ApplyTime) error {
183-
if applyTime != common.ImmediateApplyTime {
181+
func httpBasedUpdateBMCAttributes(c schemas.Client, attrs schemas.SettingsAttributes, applyTime schemas.SettingsApplyTime) error {
182+
if applyTime != schemas.ImmediateSettingsApplyTime {
184183
return fmt.Errorf("does not support scheduled apply time for BMC attributes")
185184
}
186185
if c == nil {
@@ -264,7 +263,7 @@ func isSubMap(main, sub map[string]any) bool {
264263

265264
// checkAttributes validates attributes against a filtered registry, returning
266265
// whether a reset is required and any validation errors.
267-
func checkAttributes(attrs redfish.SettingsAttributes, filtered map[string]redfish.Attribute) (reset bool, err error) {
266+
func checkAttributes(attrs schemas.SettingsAttributes, filtered map[string]schemas.Attributes) (reset bool, err error) {
268267
reset = false
269268
var errs []error
270269
for name, value := range attrs {
@@ -277,19 +276,19 @@ func checkAttributes(attrs redfish.SettingsAttributes, filtered map[string]redfi
277276
reset = true
278277
}
279278
switch entryAttribute.Type {
280-
case redfish.IntegerAttributeType:
279+
case schemas.IntegerAttributeType:
281280
if _, ok := value.(int); !ok {
282281
errs = append(errs,
283282
fmt.Errorf("attribute '%s's' value '%v' has wrong type. needed '%s' for '%v'",
284283
name, value, entryAttribute.Type, entryAttribute))
285284
}
286-
case redfish.StringAttributeType:
285+
case schemas.StringAttributeType:
287286
if _, ok := value.(string); !ok {
288287
errs = append(errs,
289288
fmt.Errorf("attribute '%s's' value '%v' has wrong type. needed '%s' for '%v'",
290289
name, value, entryAttribute.Type, entryAttribute))
291290
}
292-
case redfish.EnumerationAttributeType:
291+
case schemas.EnumerationAttributeType:
293292
if _, ok := value.(string); !ok {
294293
errs = append(errs,
295294
fmt.Errorf("attribute '%s's' value '%v' has wrong type. needed '%s' for '%v'",

bmc/redfish.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func (r *RedfishBaseBMC) ForcePowerOff(ctx context.Context, systemURI string) er
191191
}
192192

193193
// Reset performs a reset on the system using Redfish.
194-
func (r *RedfishBaseBMC) Reset(ctx context.Context, systemURI string, resetType redfish.ResetType) error {
194+
func (r *RedfishBaseBMC) Reset(ctx context.Context, systemURI string, resetType schemas.ResetType) error {
195195
system, err := r.getSystemFromUri(ctx, systemURI)
196196
if err != nil {
197197
return fmt.Errorf("failed to get systems: %w", err)
@@ -629,7 +629,7 @@ func (r *RedfishBaseBMC) checkAttributes(attrs schemas.SettingsAttributes, filte
629629
return reset, errors.Join(errs...)
630630
}
631631

632-
func (r *RedfishBaseBMC) CheckBMCAttributes(_ context.Context, _ string, _ redfish.SettingsAttributes) (bool, error) {
632+
func (r *RedfishBaseBMC) CheckBMCAttributes(_ context.Context, _ string, _ schemas.SettingsAttributes) (bool, error) {
633633
return false, fmt.Errorf("BMC attribute checking not supported for manufacturer %q", r.manufacturer)
634634
}
635635

@@ -856,20 +856,20 @@ func (r *RedfishBaseBMC) WaitForServerPowerState(ctx context.Context, systemURI
856856
}
857857

858858
// UpgradeBiosVersion is a fallback for unknown vendors. Vendor-specific structs override this.
859-
func (r *RedfishBaseBMC) UpgradeBiosVersion(_ context.Context, _ string, _ *redfish.SimpleUpdateParameters) (string, bool, error) {
859+
func (r *RedfishBaseBMC) UpgradeBiosVersion(_ context.Context, _ string, _ *schemas.UpdateServiceSimpleUpdateParameters) (string, bool, error) {
860860
return "", false, fmt.Errorf("firmware upgrade not supported for manufacturer %q", r.manufacturer)
861861
}
862862

863-
func (r *RedfishBaseBMC) GetBiosUpgradeTask(_ context.Context, _ string, _ string) (*redfish.Task, error) {
863+
func (r *RedfishBaseBMC) GetBiosUpgradeTask(_ context.Context, _ string, _ string) (*schemas.Task, error) {
864864
return nil, fmt.Errorf("firmware upgrade task not supported for manufacturer %q", r.manufacturer)
865865
}
866866

867867
// UpgradeBMCVersion is a fallback for unknown vendors. Vendor-specific structs override this.
868-
func (r *RedfishBaseBMC) UpgradeBMCVersion(_ context.Context, _ string, _ *redfish.SimpleUpdateParameters) (string, bool, error) {
868+
func (r *RedfishBaseBMC) UpgradeBMCVersion(_ context.Context, _ string, _ *schemas.UpdateServiceSimpleUpdateParameters) (string, bool, error) {
869869
return "", false, fmt.Errorf("firmware upgrade not supported for manufacturer %q", r.manufacturer)
870870
}
871871

872-
func (r *RedfishBaseBMC) GetBMCUpgradeTask(_ context.Context, _ string, _ string) (*redfish.Task, error) {
872+
func (r *RedfishBaseBMC) GetBMCUpgradeTask(_ context.Context, _ string, _ string) (*schemas.Task, error) {
873873
return nil, fmt.Errorf("firmware upgrade task not supported for manufacturer %q", r.manufacturer)
874874
}
875875

0 commit comments

Comments
 (0)