Skip to content

Commit

Permalink
install/firmware: switch to rivets for FirmwareInstall parameters, dr…
Browse files Browse the repository at this point in the history
…y-run support
  • Loading branch information
joelrebel committed Sep 28, 2023
1 parent e2253c2 commit 67f1ff0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 33 deletions.
10 changes: 7 additions & 3 deletions cmd/install/firmware_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (
"github.com/spf13/cobra"

coapiv1 "github.com/metal-toolbox/conditionorc/pkg/api/v1/types"
cotypes "github.com/metal-toolbox/conditionorc/pkg/types"
cptypes "github.com/metal-toolbox/conditionorc/pkg/types" // The condition types package being deprecated for rivets
mctl "github.com/metal-toolbox/mctl/cmd"
rctypes "github.com/metal-toolbox/rivets/condition"
serverservice "go.hollow.sh/serverservice/pkg/api/v1"
)

Expand All @@ -22,6 +23,7 @@ type installFirmwareSetFlags struct {
serverID string
forceInstall bool
skipBMCReset bool
dryRun bool
}

var (
Expand Down Expand Up @@ -61,19 +63,20 @@ func installFwSet(ctx context.Context) {
log.Fatal(err)
}

b, _ := json.Marshal(parameters{
b, _ := json.Marshal(rctypes.FirmwareInstallTaskParameters{
AssetID: serverID,
FirmwareSetID: fwSetID,
ResetBMCBeforeInstall: !flagsDefinedInstallFwSet.skipBMCReset,
ForceInstall: flagsDefinedInstallFwSet.forceInstall,
DryRun: flagsDefinedInstallFwSet.dryRun,
})

co := coapiv1.ConditionCreate{
Exclusive: true,
Parameters: json.RawMessage(b),
}

response, err := client.ServerConditionCreate(ctx, serverID, cotypes.FirmwareInstall, co)
response, err := client.ServerConditionCreate(ctx, serverID, cptypes.FirmwareInstall, co)
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -137,6 +140,7 @@ func init() {
installFirmwareSet.PersistentFlags().StringVar(&flagsDefinedInstallFwSet.serverID, "server", "", "server UUID")
installFirmwareSet.PersistentFlags().StringVar(&flagsDefinedInstallFwSet.firmwareSetID, "id", "", "firmware set UUID")
installFirmwareSet.PersistentFlags().BoolVar(&flagsDefinedInstallFwSet.forceInstall, "force", false, "force install (skips firmware version check)")
installFirmwareSet.PersistentFlags().BoolVar(&flagsDefinedInstallFwSet.dryRun, "dry-run", false, "Run install process in dry-run (skips firmware install)")
installFirmwareSet.PersistentFlags().BoolVar(&flagsDefinedInstallFwSet.skipBMCReset, "skip-bmc-reset", false, "skip BMC reset before firmware install")

if err := installFirmwareSet.MarkPersistentFlagRequired("server"); err != nil {
Expand Down
20 changes: 0 additions & 20 deletions cmd/install/types.go

This file was deleted.

13 changes: 6 additions & 7 deletions cmd/list/firmware_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ import (
)

type listFirmwareSetFlags struct {
vendor string
model string
listAll bool
vendor string
model string
}

var (
Expand All @@ -37,13 +36,14 @@ var listFirmwareSet = &cobra.Command{
}

var fwSet []serverservice.ComponentFirmwareSet
if flagsDefinedListFwSet.listAll {
fwSet, _, err = client.ListServerComponentFirmwareSet(cmd.Context(), &serverservice.ComponentFirmwareSetListParams{})

if flagsDefinedListFwSet.vendor != "" || flagsDefinedListFwSet.model != "" {
fwSet, err = mctl.FirmwareSetByVendorModel(cmd.Context(), flagsDefinedListFwSet.vendor, flagsDefinedListFwSet.model, client)
if err != nil {
log.Fatal(err)
}
} else {
fwSet, err = mctl.FirmwareSetByVendorModel(cmd.Context(), flagsDefinedListFwSet.vendor, flagsDefinedListFwSet.model, client)
fwSet, _, err = client.ListServerComponentFirmwareSet(cmd.Context(), &serverservice.ComponentFirmwareSetListParams{})
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -80,5 +80,4 @@ func init() {

listFirmwareSet.PersistentFlags().StringVar(&flagsDefinedListFwSet.vendor, "vendor", "", "filter by server vendor")
listFirmwareSet.PersistentFlags().StringVar(&flagsDefinedListFwSet.model, "model", "", "filter by server model")
listFirmwareSet.PersistentFlags().BoolVar(&flagsDefinedListFwSet.listAll, "all", false, "show all firmware sets. By default results are filtered on having labels for vendor, model and latest=true")
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/google/uuid v1.3.1
github.com/metal-toolbox/conditionorc v0.0.4
github.com/metal-toolbox/hollow-bomservice v0.1.1
github.com/metal-toolbox/rivets v0.0.0-20230904161107-77d8fb915e76
github.com/metal-toolbox/rivets v0.0.0-20230927091114-c7072205b479
github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20220510032225-4f9f17eaec4c
github.com/olekukonko/tablewriter v0.0.5
github.com/pkg/errors v0.9.1
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,10 @@ github.com/metal-toolbox/conditionorc v0.0.4 h1:P3BPeIny4Ry1o4LCMbN6BrhJvJtCY1l2
github.com/metal-toolbox/conditionorc v0.0.4/go.mod h1:S+xFRw3Baw5FW8TXDNnSSQthiwKwizyUz5fxOvTbimQ=
github.com/metal-toolbox/hollow-bomservice v0.1.1 h1:Pll/HqF8Dff0jKo9B8ywcF9bfwTBmIIQpWcAWL3mYiM=
github.com/metal-toolbox/hollow-bomservice v0.1.1/go.mod h1:v37wkZnVs/PTlfF/t6/aoMO48yE9XDCpog8kFr0R/yY=
github.com/metal-toolbox/rivets v0.0.0-20230904161107-77d8fb915e76 h1:xS2IXYekGv2wXZLxhjzXV28kVB28NkvYngrj58TNUPE=
github.com/metal-toolbox/rivets v0.0.0-20230904161107-77d8fb915e76/go.mod h1:QlGp4NUmXkSa8lhm/fFlH845kamwiOM7kiIsigVxWlg=
github.com/metal-toolbox/rivets v0.0.0-20230927052538-1c8ed77bb8ad h1:R887uppEjQVvzXTzKai7RCE1/Ks0Z+1kbPOnn2FC7Cs=
github.com/metal-toolbox/rivets v0.0.0-20230927052538-1c8ed77bb8ad/go.mod h1:QlGp4NUmXkSa8lhm/fFlH845kamwiOM7kiIsigVxWlg=
github.com/metal-toolbox/rivets v0.0.0-20230927091114-c7072205b479 h1:qRbkgUl7UZOk5V8UAjB8PG7BX2qjOeKJ7EF+t6sb9jM=
github.com/metal-toolbox/rivets v0.0.0-20230927091114-c7072205b479/go.mod h1:QlGp4NUmXkSa8lhm/fFlH845kamwiOM7kiIsigVxWlg=
github.com/microsoft/go-mssqldb v0.17.0/go.mod h1:OkoNGhGEs8EZqchVTtochlXruEhEOaO4S0d2sB5aeGQ=
github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI=
Expand Down

0 comments on commit 67f1ff0

Please sign in to comment.