Skip to content

Commit

Permalink
cmd/install: include firmware vendor, model parameters required for f…
Browse files Browse the repository at this point in the history
…irmware install
  • Loading branch information
joelrebel committed Nov 13, 2023
1 parent 35690a0 commit e1660db
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 12 deletions.
20 changes: 19 additions & 1 deletion cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ var cmdInstall = &cobra.Command{
}

var (
fwvendor string
fwmodel string
fwversion string
component string
file string
Expand All @@ -30,8 +32,22 @@ var (
func runInstall(ctx context.Context) {
l := logrus.New()
l.Level = logrus.TraceLevel + 1

p := &install.Params{
DryRun: dryrun,
Version: fwversion,
File: file,
Component: component,
Model: fwmodel,
Vendor: fwvendor,
User: user,
Pass: pass,
BmcAddr: addr,
}

installer := install.New(l)
installer.Install(ctx, addr, user, pass, component, file, fwversion, dryrun)

installer.Install(ctx, p)
}

func init() {
Expand All @@ -40,6 +56,8 @@ func init() {
cmdInstall.PersistentFlags().StringVar(&file, "file", "", "The firmware file")
cmdInstall.PersistentFlags().StringVar(&addr, "addr", "", "BMC host address")
cmdInstall.PersistentFlags().StringVar(&user, "user", "", "BMC user")
cmdInstall.PersistentFlags().StringVar(&fwvendor, "vendor", "", "Component vendor")
cmdInstall.PersistentFlags().StringVar(&fwmodel, "model", "", "Component model")
cmdInstall.PersistentFlags().StringVar(&pass, "pass", "", "BMC user password")
cmdInstall.PersistentFlags().StringVar(&component, "component", "", "The component slug the firmware applies to")

Expand Down
38 changes: 27 additions & 11 deletions internal/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,19 @@ func New(logger *logrus.Logger) *Installer {
return &Installer{logger: logger}
}

func (i *Installer) Install(ctx context.Context, bmcAddr, user, pass, component, file, version string, dryRun bool) {
type Params struct {
DryRun bool
BmcAddr string
User string
Pass string
Component string
File string
Version string
Vendor string
Model string
}

func (i *Installer) Install(ctx context.Context, params *Params) {
task := &model.Task{
ID: uuid.New(),
Parameters: rctypes.FirmwareInstallTaskParameters{},
Expand All @@ -29,28 +41,32 @@ func (i *Installer) Install(ctx context.Context, bmcAddr, user, pass, component,

// setup state machine task handler
handler := &taskHandler{
fwFile: file,
fwVersion: version,
fwComponent: component,
fwFile: params.File,
fwVersion: params.Version,
fwComponent: params.Component,
model: params.Model,
vendor: params.Vendor,
}

le := i.logger.WithFields(
logrus.Fields{
"dry-run": dryRun,
"bmc": bmcAddr,
"component": component,
"dry-run": params.DryRun,
"bmc": params.BmcAddr,
"component": params.Component,
})

handlerCtx := &sm.HandlerContext{
Dryrun: dryRun,
Dryrun: params.DryRun,
Task: task,
Ctx: ctx,
Publisher: &publisher{logger: *le},
Data: make(map[string]string),
Asset: &model.Asset{
BmcAddress: net.ParseIP(bmcAddr),
BmcUsername: user,
BmcPassword: pass,
BmcAddress: net.ParseIP(params.BmcAddr),
BmcUsername: params.User,
BmcPassword: params.Pass,
Model: params.Model,
Vendor: params.Vendor,
},
Logger: le,
}
Expand Down
4 changes: 4 additions & 0 deletions internal/install/task_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type taskHandler struct {
fwFile string
fwComponent string
fwVersion string
model string
vendor string
}

func (h *taskHandler) Init(_ sw.StateSwitch, _ sw.TransitionArgs) error {
Expand Down Expand Up @@ -194,6 +196,8 @@ func (h *taskHandler) planInstallFile(taskID string, forceInstall bool) (sm.Acti
firmware := &model.Firmware{
Component: h.fwComponent,
Version: h.fwVersion,
Models: []string{h.model},
Vendor: h.vendor,
}

actionMachines := make(sm.ActionStateMachines, 0)
Expand Down

0 comments on commit e1660db

Please sign in to comment.