Skip to content

Commit

Permalink
feat(baremetal): add a custom enum marshaling for ping status (#1024)
Browse files Browse the repository at this point in the history
  • Loading branch information
remyleone authored May 25, 2020
1 parent 6257c5e commit 96aa085
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
8 changes: 7 additions & 1 deletion internal/namespaces/baremetal/v1alpha1/custom.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package baremetal

import "github.com/scaleway/scaleway-cli/internal/core"
import (
"github.com/scaleway/scaleway-cli/internal/core"
"github.com/scaleway/scaleway-cli/internal/human"
baremetal "github.com/scaleway/scaleway-sdk-go/api/baremetal/v1alpha1"
)

func GetCommands() *core.Commands {
cmds := GetGeneratedCommands()
Expand All @@ -9,6 +13,8 @@ func GetCommands() *core.Commands {
serverWaitCommand(),
))

human.RegisterMarshalerFunc(baremetal.ServerPingStatus(0), human.EnumMarshalFunc(serverPingStatusMarshalSpecs))

cmds.MustFind("baremetal", "server", "create").Override(serverCreateBuilder)
cmds.MustFind("baremetal", "server", "install").Override(serverInstallBuilder)
cmds.MustFind("baremetal", "server", "list").Override(serverListBuilder)
Expand Down
14 changes: 14 additions & 0 deletions internal/namespaces/baremetal/v1alpha1/custom_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"reflect"
"time"

"github.com/fatih/color"
"github.com/scaleway/scaleway-cli/internal/core"
"github.com/scaleway/scaleway-cli/internal/human"
baremetal "github.com/scaleway/scaleway-sdk-go/api/baremetal/v1alpha1"
"github.com/scaleway/scaleway-sdk-go/logger"
"github.com/scaleway/scaleway-sdk-go/scw"
Expand All @@ -16,6 +18,14 @@ const (
serverActionTimeout = 20 * time.Minute
)

var (
serverPingStatusMarshalSpecs = human.EnumMarshalSpecs{
baremetal.ServerPingStatusPingStatusDown: &human.EnumMarshalSpec{Attribute: color.FgRed, Value: "down"},
baremetal.ServerPingStatusPingStatusUp: &human.EnumMarshalSpec{Attribute: color.FgGreen, Value: "up"},
baremetal.ServerPingStatusPingStatusUnknown: &human.EnumMarshalSpec{Attribute: color.Faint, Value: "unknown"},
}
)

func serverWaitCommand() *core.Command {
type serverWaitRequest struct {
ServerID string
Expand Down Expand Up @@ -152,6 +162,10 @@ func serverListBuilder(c *core.Command) *core.Command {
Label: "Tags",
FieldName: "Tags",
},
{
Label: "Ping",
FieldName: "PingStatus",
},
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ ips.1.reverse-status active
domain acc9e2cf-8828-48a7-bf3a-11744e2a33c1.fr-par-2.baremetal.scw.cloud
boot-type normal
zone fr-par-2
ping-status ping_status_up
ping-status up
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ID Name Offer Name Status Tags
0ae6f1a4-1200-4552-9251-b1e4c6dfef8a esme GP-BM1-S ready []
a6a49e51-1af3-44ae-9dd4-f7fe067f5c6b bbb.sieben.fr GP-BM1-S ready []
ID Name Offer Name Status Tags Ping
0ae6f1a4-1200-4552-9251-b1e4c6dfef8a esme GP-BM1-S ready [] unknown
a6a49e51-1af3-44ae-9dd4-f7fe067f5c6b bbb.sieben.fr GP-BM1-S ready [] up

0 comments on commit 96aa085

Please sign in to comment.