Skip to content

Commit

Permalink
update condition API endpoints (#75)
Browse files Browse the repository at this point in the history
* update condition API endpoints

* generate docs
  • Loading branch information
DoctorVin authored Dec 1, 2023
1 parent 2064b67 commit a6f2f1b
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 68 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ linters:
# additional linters
- bodyclose
- gocritic
- goerr113
- goimports
- revive
- gomnd
Expand Down
6 changes: 3 additions & 3 deletions cmd/collect/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ func statusCheck(ctx context.Context) {
log.Fatalf("parsing server id: %s", err.Error())
}

resp, err := client.ServerConditionGet(ctx, serverID, rctypes.Inventory)
resp, err := client.ServerConditionStatus(ctx, serverID)
if err != nil {
log.Fatalf("querying server conditions: %s", err.Error())
}

s, err := mctl.FormatConditionResponse(resp)
s, err := mctl.FormatConditionResponse(resp, rctypes.Inventory)
if err != nil {
log.Fatalf(err.Error())
log.Fatalf("condition response error: %s", err.Error())
}

fmt.Println(s)
Expand Down
27 changes: 17 additions & 10 deletions cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ type conditionDisplay struct {
}

// FormatConditionResponse returns a prettyish JSON formatted output that can be printed to stdout.
func FormatConditionResponse(response *coapiv1.ServerResponse) (string, error) {
func FormatConditionResponse(response *coapiv1.ServerResponse, kind rctypes.Kind) (string, error) {
if response.StatusCode != http.StatusOK {
return "", newErrUnexpectedResponse(response.StatusCode, response.Message)
}
Expand All @@ -211,18 +211,25 @@ func FormatConditionResponse(response *coapiv1.ServerResponse) (string, error) {
return "", errors.New("no record found for Condition")
}

inc := response.Records.Conditions[0]
var inc *rctypes.Condition
for _, c := range response.Records.Conditions {
if c.Kind == kind {
inc = c
}
}

if inc == nil {
return "", fmt.Errorf("response contains no condition of type %s", string(kind))
}

display := &conditionDisplay{
ID: inc.ID,
// type conversion until the Condition type is fully moved into the rivets lib
Kind: rctypes.Kind(inc.Kind),
ID: inc.ID,
Kind: inc.Kind,
Parameters: inc.Parameters,
// type conversion until the Condition type is fully moved into the rivets lib
State: rctypes.State(inc.State),
Status: inc.Status,
UpdatedAt: inc.UpdatedAt,
CreatedAt: inc.CreatedAt,
State: inc.State,
Status: inc.Status,
UpdatedAt: inc.UpdatedAt,
CreatedAt: inc.CreatedAt,
}

// XXX: seems highly unlikely that we get a response that deserializes cleanly and doesn't
Expand Down
17 changes: 5 additions & 12 deletions cmd/get/condition.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import (
"github.com/google/uuid"
mctl "github.com/metal-toolbox/mctl/cmd"
"github.com/metal-toolbox/mctl/internal/app"
rctypes "github.com/metal-toolbox/rivets/condition"
"github.com/spf13/cobra"
)

type getConditionFlags struct {
// server UUID
id string
kind string
id string
}

var (
Expand All @@ -22,7 +20,7 @@ var (

var getCondition = &cobra.Command{
Use: "condition",
Short: "get server condition",
Short: "get the last server conditions performed",
Run: func(cmd *cobra.Command, args []string) {
theApp := mctl.MustCreateApp(cmd.Context())

Expand All @@ -36,7 +34,7 @@ var getCondition = &cobra.Command{
log.Fatal(err)
}

response, err := client.ServerConditionGet(cmd.Context(), id, rctypes.Kind(flagsDefinedGetCondition.kind))
response, err := client.ServerConditionStatus(cmd.Context(), id)
if err != nil {
log.Fatal(err)
}
Expand All @@ -48,14 +46,9 @@ var getCondition = &cobra.Command{
func init() {
flagsDefinedGetCondition = &getConditionFlags{}

getCondition.PersistentFlags().StringVar(&flagsDefinedGetCondition.id, "server", "", "server UUID")
getCondition.PersistentFlags().StringVar(&flagsDefinedGetCondition.kind, "kind", "", "condition kind")
getCondition.Flags().StringVarP(&flagsDefinedGetCondition.id, "server", "s", "", "server UUID")

if err := getCondition.MarkPersistentFlagRequired("server"); err != nil {
log.Fatal(err)
}

if err := getCondition.MarkPersistentFlagRequired("kind"); err != nil {
if err := getCondition.MarkFlagRequired("server"); err != nil {
log.Fatal(err)
}

Expand Down
11 changes: 2 additions & 9 deletions cmd/install/firmware_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package install

import (
"context"
"encoding/json"
"log"
"strings"

Expand All @@ -11,7 +10,6 @@ import (
"github.com/pkg/errors"
"github.com/spf13/cobra"

coapiv1 "github.com/metal-toolbox/conditionorc/pkg/api/v1/types"
mctl "github.com/metal-toolbox/mctl/cmd"
rctypes "github.com/metal-toolbox/rivets/condition"
serverservice "go.hollow.sh/serverservice/pkg/api/v1"
Expand Down Expand Up @@ -63,21 +61,16 @@ func installFwSet(ctx context.Context) {
log.Fatal(err)
}

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

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

response, err := client.ServerConditionCreate(ctx, serverID, rctypes.FirmwareInstall, co)
response, err := client.ServerFirmwareInstall(ctx, params)
if err != nil {
log.Fatal(err)
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/install/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ func statusCheck(ctx context.Context) {
log.Fatalf("parsing server id: %s", err.Error())
}

resp, err := client.ServerConditionGet(ctx, serverID, rctypes.FirmwareInstall)
resp, err := client.ServerConditionStatus(ctx, serverID)
if err != nil {
log.Fatalf("querying server conditions: %s", err.Error())
}

s, err := mctl.FormatConditionResponse(resp)
s, err := mctl.FormatConditionResponse(resp, rctypes.FirmwareInstall)
if err != nil {
log.Fatalf("error formating condition response: %s", err.Error())
log.Fatalf("condition response error: %s", err.Error())
}

fmt.Println(s)
Expand Down
2 changes: 1 addition & 1 deletion docs/mctl_get.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ mctl get [flags]
* [mctl get bios-config](mctl_get_bios-config.md) - Get bios configuration information for a server
* [mctl get bom](mctl_get_bom.md) - Get bom object by AOC or BMC Addr
* [mctl get component](mctl_get_component.md) - get server components
* [mctl get condition](mctl_get_condition.md) - get server condition
* [mctl get condition](mctl_get_condition.md) - get the last server conditions performed
* [mctl get firmware](mctl_get_firmware.md) - Get information for given firmware identifier
* [mctl get firmware-set](mctl_get_firmware-set.md) - Get information for given firmware set identifier

5 changes: 2 additions & 3 deletions docs/mctl_get_condition.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## mctl get condition

get server condition
get the last server conditions performed

```
mctl get condition [flags]
Expand All @@ -12,8 +12,7 @@ mctl get condition [flags]

```
-h, --help help for condition
--kind string condition kind
--server string server UUID
-s, --server string server UUID
```

### Options inherited from parent commands
Expand Down
72 changes: 46 additions & 26 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,68 @@ require (
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/google/uuid v1.4.0
github.com/metal-toolbox/conditionorc v0.1.12
github.com/metal-toolbox/conditionorc v0.1.13-0.20231130145836-ca97b7ffa9c1
github.com/metal-toolbox/hollow-bomservice v0.1.1
github.com/metal-toolbox/rivets v0.0.0-20231020103738-10fc2993b885
github.com/metal-toolbox/rivets v0.1.1
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
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
github.com/spf13/cobra v1.7.0
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.17.0
github.com/stretchr/testify v1.8.4
github.com/zalando/go-keyring v0.2.1
go.hollow.sh/serverservice v0.16.2
golang.org/x/net v0.17.0
golang.org/x/oauth2 v0.13.0
golang.org/x/net v0.19.0
golang.org/x/oauth2 v0.15.0
gopkg.in/square/go-jose.v2 v2.6.0
)

require (
github.com/KyleBanks/depth v1.2.1 // indirect
github.com/alessio/shellescape v1.4.1 // indirect
github.com/banzaicloud/logrus-runtime-formatter v0.0.0-20190729070250-5ae5475bae5e // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bytedance/sonic v1.10.2 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/cockroachdb/cockroach-go/v2 v2.3.5 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/danieljoos/wincred v1.1.0 // indirect
github.com/equinix-labs/otel-init-go v0.0.9 // indirect
github.com/ericlagergren/decimal v0.0.0-20221120152707-495c53812d05 // indirect
github.com/felixge/httpsnoop v1.0.3 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/friendsofgo/errors v0.9.2 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.9.1 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.20.0 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/spec v0.20.9 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.15.5 // indirect
github.com/go-playground/validator/v10 v10.16.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/godbus/dbus/v5 v5.0.6 // indirect
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/googleapis/gax-go/v2 v2.12.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/gosimple/slug v1.13.1 // indirect
github.com/gosimple/unidecode v1.0.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-retryablehttp v0.7.4 // indirect
github.com/hashicorp/go-retryablehttp v0.7.5 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
Expand All @@ -73,15 +81,18 @@ require (
github.com/jackc/pgtype v1.14.0 // indirect
github.com/jackc/pgx/v4 v4.18.1 // indirect
github.com/jmoiron/sqlx v1.3.5 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.2 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/klauspost/compress v1.17.3 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/metal-toolbox/flasher v0.2.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
Expand All @@ -101,10 +112,13 @@ require (
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/slack-go/slack v0.12.3 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/swaggo/files v1.0.1 // indirect
github.com/swaggo/gin-swagger v1.6.0 // indirect
github.com/swaggo/swag v1.16.3-0.20230925065629-1460377e6729 // indirect
github.com/tealeg/xlsx v1.0.5 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.11 // indirect
Expand All @@ -117,22 +131,28 @@ require (
github.com/volatiletech/strmangle v0.0.5 // indirect
go.hollow.sh/toolbox v0.6.2 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 // indirect
go.opentelemetry.io/otel v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.19.0 // indirect
go.opentelemetry.io/otel/trace v1.19.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.46.1 // indirect
go.opentelemetry.io/otel v1.21.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.21.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.21.0 // indirect
go.opentelemetry.io/otel/metric v1.21.0 // indirect
go.opentelemetry.io/otel/sdk v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.21.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.26.0 // indirect
gocloud.dev v0.34.0 // indirect
golang.org/x/arch v0.5.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/arch v0.6.0 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/exp v0.0.0-20231127185646-65229373498e // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.16.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/api v0.148.0 // indirect
google.golang.org/api v0.152.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231127180814-3a041ad873d4 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231127180814-3a041ad873d4 // indirect
google.golang.org/grpc v1.59.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
Loading

0 comments on commit a6f2f1b

Please sign in to comment.