Skip to content

Commit

Permalink
PR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeschuurmans committed Oct 9, 2024
1 parent 670f07b commit 06b860f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
15 changes: 8 additions & 7 deletions internal/bioscfg/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,20 @@ import (
rctypes "github.com/metal-toolbox/rivets/condition"
)

func (th *TaskHandler) HandleAction(ctx context.Context) error {
// handleAction completes the condition task based on the condition action
func (th *TaskHandler) handleAction(ctx context.Context) error {
switch th.task.Parameters.Action {
case rctypes.ResetConfig:
return th.ResetBiosConfig(ctx)
return th.resetBiosConfig(ctx)
case rctypes.SetConfig:
return th.SetBiosConfig(ctx)
return th.setBiosConfig(ctx)
default:
return th.failedWithError(ctx, string(th.task.Parameters.Action), errUnsupportedAction)
}
}

// ResetBios reset the bios of the server
func (th *TaskHandler) ResetBiosConfig(ctx context.Context) error {
// resetBiosConfig resets the bios of the server
func (th *TaskHandler) resetBiosConfig(ctx context.Context) error {
// Get Power State
state, err := th.bmcClient.GetPowerState(ctx)
if err != nil {
Expand Down Expand Up @@ -57,8 +58,8 @@ func (th *TaskHandler) ResetBiosConfig(ctx context.Context) error {
return th.successful(ctx, "skipping server reboot, not on")
}

// UploadConfig set BIOS Config
func (th *TaskHandler) SetBiosConfig(ctx context.Context) error {
// setBiosConfig sets BIOS Config
func (th *TaskHandler) setBiosConfig(ctx context.Context) error {
var configURL = ""
if th.task.Parameters.BiosConfigURL != nil {
configURL = th.task.Parameters.BiosConfigURL.String()
Expand Down
8 changes: 4 additions & 4 deletions internal/bioscfg/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (th *TaskHandler) HandleTask(ctx context.Context, genTask *rctypes.Task[any
th.publisher = publisher

// Ungeneric the task
th.task, err = NewTask(genTask)
th.task, err = newTask(genTask)
if err != nil {
th.logger.WithFields(logrus.Fields{
"conditionID": genTask.ID,
Expand Down Expand Up @@ -91,10 +91,10 @@ func (th *TaskHandler) HandleTask(ctx context.Context, genTask *rctypes.Task[any
}
}()

return th.Run(ctx)
return th.run(ctx)
}

func (th *TaskHandler) Run(ctx context.Context) error {
func (th *TaskHandler) run(ctx context.Context) error {
ctx, span := otel.Tracer(pkgName).Start(
ctx,
"TaskHandler.Run",
Expand All @@ -108,5 +108,5 @@ func (th *TaskHandler) Run(ctx context.Context) error {
return err
}

return th.HandleAction(ctx)
return th.handleAction(ctx)
}
2 changes: 1 addition & 1 deletion internal/bioscfg/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (th *TaskHandler) publish(ctx context.Context, status string, state rctypes
th.task.State = state
th.task.Status.Append(status)

genTask, err := th.task.ToGeneric()
genTask, err := th.task.toGeneric()
if err != nil {
th.logger.WithError(errTaskConv).Error()
return err
Expand Down
6 changes: 4 additions & 2 deletions internal/bioscfg/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (

type Task rctypes.Task[*rctypes.BiosControlTaskParameters, json.RawMessage]

func NewTask(task *rctypes.Task[any, any]) (*Task, error) {
// newTask converts a Generic Condition Task to a BiosControl Task
func newTask(task *rctypes.Task[any, any]) (*Task, error) {
paramsJSON, ok := task.Parameters.(json.RawMessage)
if !ok {
return nil, errInvalidConditionParams
Expand Down Expand Up @@ -52,7 +53,8 @@ func NewTask(task *rctypes.Task[any, any]) (*Task, error) {
}, nil
}

func (task *Task) ToGeneric() (*rctypes.Task[any, any], error) {
// toGeneric converts a BiosControl Task to a Generic Condition Task
func (task *Task) toGeneric() (*rctypes.Task[any, any], error) {
paramsJSON, err := task.Parameters.Marshal()
if err != nil {
return nil, errors.Wrap(errTaskConv, err.Error()+": Task.Parameters")
Expand Down

0 comments on commit 06b860f

Please sign in to comment.