Skip to content

Commit

Permalink
cmd/install: Add a --plan-only flag to print the firmware install plan
Browse files Browse the repository at this point in the history
  • Loading branch information
joelrebel committed Dec 5, 2023
1 parent b6bfb74 commit d02ed94
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
3 changes: 3 additions & 0 deletions cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var (
user string
pass string
force bool
onlyPlan bool
)

func runInstall(ctx context.Context) {
Expand Down Expand Up @@ -63,6 +64,7 @@ func runInstall(ctx context.Context) {
Pass: pass,
BmcAddr: addr,
Force: force,
OnlyPlan: onlyPlan,
}

installer := install.New(flasher.Logger)
Expand All @@ -71,6 +73,7 @@ func runInstall(ctx context.Context) {
}

func init() {
cmdInstall.Flags().BoolVarP(&onlyPlan, "only-plan", "", false, "only plan and list the install plan")
cmdInstall.Flags().BoolVarP(&dryrun, "dry-run", "", false, "dry run install")
cmdInstall.Flags().BoolVarP(&force, "force", "", false, "force install, skip checking existing version")
cmdInstall.Flags().StringVar(&fwversion, "version", "", "The version of the firmware being installed")
Expand Down
2 changes: 2 additions & 0 deletions internal/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Params struct {
Model string
DryRun bool
Force bool
OnlyPlan bool
}

func (i *Installer) Install(ctx context.Context, params *Params) {
Expand All @@ -58,6 +59,7 @@ func (i *Installer) Install(ctx context.Context, params *Params) {
fwComponent: params.Component,
model: params.Model,
vendor: params.Vendor,
onlyPlan: params.OnlyPlan,
}

le := i.logger.WithFields(
Expand Down
29 changes: 24 additions & 5 deletions internal/install/task_handler.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package install

import (
"fmt"

"github.com/bmc-toolbox/common"
sw "github.com/filanov/stateswitch"
"github.com/metal-toolbox/flasher/internal/model"
Expand All @@ -18,11 +20,13 @@ var (

// taskHandler implements the taskTransitionHandler methods
type taskHandler struct {
fwFile string
fwComponent string
fwVersion string
model string
vendor string
fwFile string
fwComponent string
fwVersion string
model string
vendor string
onlyPlan bool
bmcResetPreInstall bool
}

func (h *taskHandler) Init(_ sw.StateSwitch, args sw.TransitionArgs) error {
Expand Down Expand Up @@ -92,6 +96,17 @@ func (h *taskHandler) Plan(t sw.StateSwitch, args sw.TransitionArgs) error {
return nil
}

func (h *taskHandler) listPlan(tctx *sm.HandlerContext) error {
tctx.Logger.WithField("plan.actions", len(tctx.ActionStateMachines)).Info("only listing the plan")
for _, actionSM := range tctx.ActionStateMachines {
for _, tx := range actionSM.TransitionOrder() {
fmt.Println(tx)
}
}

return nil
}

func (h *taskHandler) Run(t sw.StateSwitch, args sw.TransitionArgs) error {
tctx, ok := args.(*sm.HandlerContext)
if !ok {
Expand All @@ -103,6 +118,10 @@ func (h *taskHandler) Run(t sw.StateSwitch, args sw.TransitionArgs) error {
return errors.Wrap(ErrSaveTask, ErrTaskTypeAssertion.Error())
}

if h.onlyPlan {
return h.listPlan(tctx)
}

tctx.Logger.WithField("plan.actions", len(tctx.ActionStateMachines)).Debug("running the plan")

// each actionSM (state machine) corresponds to a firmware to be installed
Expand Down

0 comments on commit d02ed94

Please sign in to comment.