Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show power metrics of machines in ipmi -o wide #180

Merged
merged 2 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions cmd/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (c *test[R]) testCmd(t *testing.T) {
require.NotEmpty(t, c.cmd, "cmd must not be empty")

if c.wantErr != nil {
mock, _, config := c.newMockConfig(t)
_, _, config := c.newMockConfig(t)

cmd := newRootCmd(config)
os.Args = append([]string{binaryName}, c.cmd(c.want)...)
Expand All @@ -73,13 +73,12 @@ func (c *test[R]) testCmd(t *testing.T) {
t.Errorf("error diff (+got -want):\n %s", diff)
}

mock.AssertExpectations(t)
}

for _, format := range outputFormats(c) {
format := format
t.Run(fmt.Sprintf("%v", format.Args()), func(t *testing.T) {
mock, out, config := c.newMockConfig(t)
_, out, config := c.newMockConfig(t)

viper.Reset()

Expand All @@ -91,14 +90,12 @@ func (c *test[R]) testCmd(t *testing.T) {
assert.NoError(t, err)

format.Validate(t, out.Bytes())

mock.AssertExpectations(t)
})
}
}

func (c *test[R]) newMockConfig(t *testing.T) (*client.MetalMockClient, *bytes.Buffer, *config) {
mock, client := client.NewMetalMockClient(c.mocks)
mock, client := client.NewMetalMockClient(t, c.mocks)

fs := afero.NewMemMapFs()
if c.fsMocks != nil {
Expand Down
12 changes: 6 additions & 6 deletions cmd/sizeimageconstraint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func Test_SizeImageConstraintCmd_MultiResult(t *testing.T) {
return []string{"size", "imageconstraint", "list"}
},
mocks: &client.MetalMockFns{
SizeImageConstraint: func(mock *mock.Mock) {
Sizeimageconstraint: func(mock *mock.Mock) {
mock.On("ListSizeImageConstraints", testcommon.MatchIgnoreContext(t, sizeimageconstraint.NewListSizeImageConstraintsParams()), nil).Return(&sizeimageconstraint.ListSizeImageConstraintsOK{
Payload: []*models.V1SizeImageConstraintResponse{
sic2,
Expand Down Expand Up @@ -89,7 +89,7 @@ ID NAME DESCRIPTION IMAGE CONSTRAINT
require.NoError(t, afero.WriteFile(fs, "/file.yaml", mustMarshalToMultiYAML(t, want), 0755))
},
mocks: &client.MetalMockFns{
SizeImageConstraint: func(mock *mock.Mock) {
Sizeimageconstraint: func(mock *mock.Mock) {
mock.On("CreateSizeImageConstraint", testcommon.MatchIgnoreContext(t, sizeimageconstraint.NewCreateSizeImageConstraintParams().WithBody(sizeImageContraintResponseToCreate(sic1))), nil).Return(nil, &sizeimageconstraint.CreateSizeImageConstraintConflict{}).Once()
mock.On("UpdateSizeImageConstraint", testcommon.MatchIgnoreContext(t, sizeimageconstraint.NewUpdateSizeImageConstraintParams().WithBody(sizeImageContraintResponseToUpdate(sic1))), nil).Return(&sizeimageconstraint.UpdateSizeImageConstraintOK{
Payload: sic1,
Expand Down Expand Up @@ -118,7 +118,7 @@ func Test_SizeImageConstraintCmd_SingleResult(t *testing.T) {
return []string{"size", "imageconstraint", "describe", *want.ID}
},
mocks: &client.MetalMockFns{
SizeImageConstraint: func(mock *mock.Mock) {
Sizeimageconstraint: func(mock *mock.Mock) {
mock.On("FindSizeImageConstraint", testcommon.MatchIgnoreContext(t, sizeimageconstraint.NewFindSizeImageConstraintParams().WithID(*sic1.ID)), nil).Return(&sizeimageconstraint.FindSizeImageConstraintOK{
Payload: sic1,
}, nil)
Expand Down Expand Up @@ -149,7 +149,7 @@ ID NAME DESCRIPTION IMAGE CONSTRAINT
return []string{"size", "imageconstraint", "rm", *want.ID}
},
mocks: &client.MetalMockFns{
SizeImageConstraint: func(mock *mock.Mock) {
Sizeimageconstraint: func(mock *mock.Mock) {
mock.On("DeleteSizeImageConstraint", testcommon.MatchIgnoreContext(t, sizeimageconstraint.NewDeleteSizeImageConstraintParams().WithID(*sic1.ID)), nil).Return(&sizeimageconstraint.DeleteSizeImageConstraintOK{
Payload: sic1,
}, nil)
Expand All @@ -166,7 +166,7 @@ ID NAME DESCRIPTION IMAGE CONSTRAINT
require.NoError(t, afero.WriteFile(fs, "/file.yaml", mustMarshal(t, want), 0755))
},
mocks: &client.MetalMockFns{
SizeImageConstraint: func(mock *mock.Mock) {
Sizeimageconstraint: func(mock *mock.Mock) {
mock.On("CreateSizeImageConstraint", testcommon.MatchIgnoreContext(t, sizeimageconstraint.NewCreateSizeImageConstraintParams().WithBody(sizeImageContraintResponseToCreate(sic1))), nil).Return(&sizeimageconstraint.CreateSizeImageConstraintCreated{
Payload: sic1,
}, nil)
Expand All @@ -183,7 +183,7 @@ ID NAME DESCRIPTION IMAGE CONSTRAINT
require.NoError(t, afero.WriteFile(fs, "/file.yaml", mustMarshal(t, want), 0755))
},
mocks: &client.MetalMockFns{
SizeImageConstraint: func(mock *mock.Mock) {
Sizeimageconstraint: func(mock *mock.Mock) {
mock.On("UpdateSizeImageConstraint", testcommon.MatchIgnoreContext(t, sizeimageconstraint.NewUpdateSizeImageConstraintParams().WithBody(sizeImageContraintResponseToUpdate(sic1))), nil).Return(&sizeimageconstraint.UpdateSizeImageConstraintOK{
Payload: sic1,
}, nil)
Expand Down
8 changes: 4 additions & 4 deletions cmd/switch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func Test_SwitchCmd_MultiResult(t *testing.T) {
return []string{"switch", "list"}
},
mocks: &client.MetalMockFns{
Switch: func(mock *mock.Mock) {
SwitchOperations: func(mock *mock.Mock) {
mock.On("ListSwitches", testcommon.MatchIgnoreContext(t, switch_operations.NewListSwitchesParams()), nil).Return(&switch_operations.ListSwitchesOK{
Payload: []*models.V1SwitchResponse{
switch2,
Expand Down Expand Up @@ -162,7 +162,7 @@ func Test_SwitchCmd_SingleResult(t *testing.T) {
return []string{"switch", "describe", *want.ID}
},
mocks: &client.MetalMockFns{
Switch: func(mock *mock.Mock) {
SwitchOperations: func(mock *mock.Mock) {
mock.On("FindSwitch", testcommon.MatchIgnoreContext(t, switch_operations.NewFindSwitchParams().WithID(*switch1.ID)), nil).Return(&switch_operations.FindSwitchOK{
Payload: switch1,
}, nil)
Expand Down Expand Up @@ -193,7 +193,7 @@ ID PARTITION RACK MODE LAST SYNC SYNC DURATION LAST SYNC ER
return []string{"switch", "rm", *want.ID}
},
mocks: &client.MetalMockFns{
Switch: func(mock *mock.Mock) {
SwitchOperations: func(mock *mock.Mock) {
mock.On("DeleteSwitch", testcommon.MatchIgnoreContext(t, switch_operations.NewDeleteSwitchParams().WithID(*switch1.ID)), nil).Return(&switch_operations.DeleteSwitchOK{
Payload: switch1,
}, nil)
Expand All @@ -210,7 +210,7 @@ ID PARTITION RACK MODE LAST SYNC SYNC DURATION LAST SYNC ER
require.NoError(t, afero.WriteFile(fs, "/file.yaml", mustMarshal(t, want), 0755))
},
mocks: &client.MetalMockFns{
Switch: func(mock *mock.Mock) {
SwitchOperations: func(mock *mock.Mock) {
mock.On("UpdateSwitch", testcommon.MatchIgnoreContext(t, switch_operations.NewUpdateSwitchParams().WithBody(switchResponseToUpdate(switch1))), nil).Return(&switch_operations.UpdateSwitchOK{
Payload: switch1,
}, nil)
Expand Down
4 changes: 4 additions & 0 deletions cmd/tableprinters/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"
"time"

"github.com/dustin/go-humanize"
"github.com/fatih/color"
"github.com/metal-stack/metal-go/api/models"
"github.com/metal-stack/metal-lib/pkg/genericcli"
Expand Down Expand Up @@ -214,6 +215,9 @@ func extractPowerState(ipmi *models.V1MachineIPMI) (short, wide string) {
short = color.WhiteString(dot)
}
wide = state
if ipmi.Powermetric != nil {
wide = wide + " " + humanize.SI(float64(*ipmi.Powermetric.Averageconsumedwatts), "W")
}

return short, wide
}
Expand Down
52 changes: 28 additions & 24 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ go 1.19

require (
bou.ke/monkey v1.0.2
github.com/avast/retry-go/v4 v4.3.0
github.com/dustin/go-humanize v1.0.0
github.com/avast/retry-go/v4 v4.3.2
github.com/dustin/go-humanize v1.0.1
github.com/fatih/color v1.13.0
github.com/go-openapi/runtime v0.24.2
github.com/go-openapi/runtime v0.25.0
github.com/go-openapi/strfmt v0.21.3
github.com/google/go-cmp v0.5.9
github.com/metal-stack/metal-go v0.21.4
github.com/metal-stack/metal-go v0.21.5
github.com/metal-stack/metal-lib v0.11.2
github.com/metal-stack/updater v1.1.3
github.com/metal-stack/updater v1.1.4
github.com/metal-stack/v v1.0.3
github.com/olekukonko/tablewriter v0.0.5
github.com/spf13/afero v1.9.2
github.com/spf13/afero v1.9.3
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.14.0
github.com/stretchr/testify v1.8.1
github.com/tailscale/golang-x-crypto v0.0.0-20221102133106-bc99ab8c2d17
go.uber.org/zap v1.23.0
golang.org/x/exp v0.0.0-20221109134031-9ce248df8de5
golang.org/x/term v0.2.0
go.uber.org/zap v1.24.0
golang.org/x/exp v0.0.0-20230116083435-1de6713980de
golang.org/x/term v0.4.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280
tailscale.com v1.34.0
Expand All @@ -32,8 +32,8 @@ require (
require (
filippo.io/edwards25519 v1.0.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/Masterminds/sprig/v3 v3.2.2 // indirect
github.com/Masterminds/semver/v3 v3.2.0 // indirect
github.com/Masterminds/sprig/v3 v3.2.3 // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/akutz/memconn v0.1.0 // indirect
Expand All @@ -60,9 +60,11 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/emicklei/go-restful-openapi/v2 v2.9.1 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/emicklei/go-restful/v3 v3.10.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fxamacker/cbor/v2 v2.4.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/analysis v0.21.4 // indirect
github.com/go-openapi/errors v0.20.3 // indirect
Expand All @@ -78,13 +80,13 @@ require (
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/go-github/v32 v32.1.0 // indirect
github.com/google/go-github/v48 v48.0.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hdevalence/ed25519consensus v0.0.0-20220222234857-c00d1f31bab3 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/huandu/xstrings v1.3.3 // indirect
github.com/icza/dyno v0.0.0-20220812133438-f0b6f8a18845 // indirect
github.com/illarion/gonotify v1.0.1 // indirect
github.com/imdario/mergo v0.3.13 // indirect
Expand Down Expand Up @@ -112,7 +114,7 @@ require (
github.com/mdlayher/netlink v1.6.0 // indirect
github.com/mdlayher/sdnotify v1.0.0 // indirect
github.com/mdlayher/socket v0.2.3 // indirect
github.com/metal-stack/security v0.6.5 // indirect
github.com/metal-stack/security v0.6.6 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-ps v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
Expand Down Expand Up @@ -141,19 +143,21 @@ require (
github.com/vishvananda/netns v0.0.1 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.mongodb.org/mongo-driver v1.11.0 // indirect
go.opentelemetry.io/otel v1.11.1 // indirect
go.opentelemetry.io/otel/trace v1.11.1 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
go4.org/mem v0.0.0-20220726221520-4f986261bf13 // indirect
go4.org/netipx v0.0.0-20220925034521-797b0c90d8ab // indirect
golang.org/x/crypto v0.2.0 // indirect
golang.org/x/mod v0.6.0 // indirect
golang.org/x/net v0.2.0 // indirect
golang.org/x/oauth2 v0.2.0 // indirect
golang.org/x/crypto v0.5.0 // indirect
golang.org/x/mod v0.7.0 // indirect
golang.org/x/net v0.5.0 // indirect
golang.org/x/oauth2 v0.4.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/text v0.4.0 // indirect
golang.org/x/time v0.2.0 // indirect
golang.org/x/tools v0.2.0 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/text v0.6.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.5.0 // indirect
golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224 // indirect
golang.zx2c4.com/wireguard v0.0.0-20220920152132-bb719d3a6e2c // indirect
golang.zx2c4.com/wireguard/windows v0.5.3 // indirect
Expand Down
Loading