Skip to content

Commit

Permalink
report created_at and updated_at from condition API (#70)
Browse files Browse the repository at this point in the history
* report created_at and updated_at from condition API

* unify server flag handling across commands
  • Loading branch information
DoctorVin authored Nov 17, 2023
1 parent 225704a commit ff4fc3d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 27 deletions.
11 changes: 11 additions & 0 deletions cmd/collect/collect.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package collect

import (
"log"

"github.com/metal-toolbox/mctl/cmd"
"github.com/spf13/cobra"
)

var serverIDStr string

var collect = &cobra.Command{
Use: "collect",
Short: "Collect current server firmware status and bios configuration",
Expand All @@ -16,4 +20,11 @@ var collect = &cobra.Command{

func init() {
cmd.RootCmd.AddCommand(collect)

pflags := collect.PersistentFlags()
pflags.StringVarP(&serverIDStr, "server", "s", "", "server id (typically a UUID)")

if err := collect.MarkPersistentFlagRequired("server"); err != nil {
log.Fatalf("marking server flag as required: %s", err.Error())
}
}
18 changes: 7 additions & 11 deletions cmd/collect/inventory.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
)

type collectInventoryFlags struct {
serverID string
skipFirmwareStatusCollect bool
skipBiosConfigCollect bool
}
Expand All @@ -26,9 +25,9 @@ var (
)

var collectInventoryCmd = &cobra.Command{
Use: "inventory",
Use: "inventory --server | -s <server uuid>",
Short: "Collect current server firmware status and bios configuration",
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
collectInventory(cmd.Context())

},
Expand All @@ -37,7 +36,7 @@ var collectInventoryCmd = &cobra.Command{
func collectInventory(ctx context.Context) {
theApp := mctl.MustCreateApp(ctx)

serverID, err := uuid.Parse(flagsDefinedCollectInventory.serverID)
serverID, err := uuid.Parse(serverIDStr)
if err != nil {
log.Fatal(err)
}
Expand Down Expand Up @@ -80,11 +79,8 @@ func init() {
flagsDefinedCollectInventory = &collectInventoryFlags{}

collect.AddCommand(collectInventoryCmd)
collectInventoryCmd.PersistentFlags().StringVar(&flagsDefinedCollectInventory.serverID, "server", "", "server UUID")
collectInventoryCmd.PersistentFlags().BoolVar(&flagsDefinedCollectInventory.skipFirmwareStatusCollect, "skip-fw-status", false, "Skip firmware status data collection")
collectInventoryCmd.PersistentFlags().BoolVar(&flagsDefinedCollectInventory.skipBiosConfigCollect, "skip-bios-config", false, "Skip BIOS configuration data collection")

if err := collectInventoryCmd.MarkPersistentFlagRequired("server"); err != nil {
log.Fatal(err)
}
collectInventoryCmd.PersistentFlags().BoolVar(&flagsDefinedCollectInventory.skipFirmwareStatusCollect,
"skip-fw-status", false, "Skip firmware status data collection")
collectInventoryCmd.PersistentFlags().BoolVar(&flagsDefinedCollectInventory.skipBiosConfigCollect,
"skip-bios-config", false, "Skip BIOS configuration data collection")
}
9 changes: 0 additions & 9 deletions cmd/collect/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
rctypes "github.com/metal-toolbox/rivets/condition"
)

var serverIDStr string

var inventoryStatus = &cobra.Command{
Use: "status --server | -s <server uuid>",
Short: "check the progress of a inventory collection for a server",
Expand Down Expand Up @@ -51,12 +49,5 @@ func statusCheck(ctx context.Context) {
}

func init() {
flags := inventoryStatus.Flags()
flags.StringVarP(&serverIDStr, "server", "s", "", "server id (typically a UUID)")

if err := inventoryStatus.MarkFlagRequired("server"); err != nil {
log.Fatalf("marking server flag as required: %s", err.Error())
}

collect.AddCommand(inventoryStatus)
}
6 changes: 4 additions & 2 deletions cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,10 @@ func FormatConditionResponse(response *coapiv1.ServerResponse) (string, error) {
Kind: rctypes.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,
State: rctypes.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
3 changes: 2 additions & 1 deletion docs/mctl_collect.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ mctl collect [flags]
### Options

```
-h, --help help for collect
-h, --help help for collect
-s, --server string server id (typically a UUID)
```

### Options inherited from parent commands
Expand Down
4 changes: 2 additions & 2 deletions docs/mctl_collect_inventory.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
Collect current server firmware status and bios configuration

```
mctl collect inventory [flags]
mctl collect inventory --server | -s <server uuid> [flags]
```

### Options

```
-h, --help help for inventory
--server string server UUID
--skip-bios-config Skip BIOS configuration data collection
--skip-fw-status Skip firmware status data collection
```
Expand All @@ -22,6 +21,7 @@ mctl collect inventory [flags]
```
--config string config file (default is $XDG_CONFIG_HOME/mctl/config.yml)
--reauth re-authenticate with oauth services
-s, --server string server id (typically a UUID)
```

### SEE ALSO
Expand Down
4 changes: 2 additions & 2 deletions docs/mctl_collect_status.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ mctl collect status --server | -s <server uuid> [flags]
### Options

```
-h, --help help for status
-s, --server string server id (typically a UUID)
-h, --help help for status
```

### Options inherited from parent commands

```
--config string config file (default is $XDG_CONFIG_HOME/mctl/config.yml)
--reauth re-authenticate with oauth services
-s, --server string server id (typically a UUID)
```

### SEE ALSO
Expand Down

0 comments on commit ff4fc3d

Please sign in to comment.