Skip to content

Commit

Permalink
Report "pool ls" quantities in human readable form by default
Browse files Browse the repository at this point in the history
Mangle the items received from the api to add bin_free,
bin_used and bin_size as 3-digits+unit approximation of
the original int64 values.

Example:

{
        "bin_free": "2.12g",
        "bin_size": "30.3g",
        "bin_used": "26.6g",
}

For original values:

{
        "free": 2278817792,
        "size": 32574881792,
        "used": 28615196672,
}
  • Loading branch information
cvaroqui committed Sep 22, 2023
1 parent b5029f9 commit dc824e6
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions core/commands/pool_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/opensvc/om3/core/output"
"github.com/opensvc/om3/core/rawconfig"
"github.com/opensvc/om3/daemon/api"
"github.com/opensvc/om3/util/sizeconv"
"github.com/opensvc/om3/util/unstructured"
)

type (
Expand All @@ -18,6 +20,25 @@ type (
)

func (t *CmdPoolLs) Run() error {

render := func(items api.PoolItems) {
lines := make(unstructured.List, len(items))
for i, item := range items {
u := item.Unstructured()
u["bin_free"] = sizeconv.BSizeCompact(float64(item.Free))
u["bin_used"] = sizeconv.BSizeCompact(float64(item.Used))
u["bin_size"] = sizeconv.BSizeCompact(float64(item.Size))
lines[i] = u
}
output.Renderer{
DefaultOutput: "tab=NAME:name,TYPE:type,CAPABILITIES:capabilities[*],HEAD:head,VOLUME_COUNT:volume_count,BIN_SIZE:bin_size,BIN_USED:bin_used,BIN_FREE:bin_free",
Output: t.Output,
Color: t.Color,
Data: lines,
Colorize: rawconfig.Colorize,
}.Print()
}

c, err := client.New(client.WithURL(t.Server))
if err != nil {
return err
Expand All @@ -32,13 +53,7 @@ func (t *CmdPoolLs) Run() error {
}
switch resp.StatusCode() {
case 200:
output.Renderer{
DefaultOutput: "tab=NAME:name,TYPE:type,CAPABILITIES:capabilities[*],HEAD:head,VOLUME_COUNT:volume_count,SIZE:size,USED:used,FREE:free",
Output: t.Output,
Color: t.Color,
Data: resp.JSON200.Items,
Colorize: rawconfig.Colorize,
}.Print()
render(resp.JSON200.Items)
case 401:
return fmt.Errorf("%s", resp.JSON401)
case 403:
Expand Down

0 comments on commit dc824e6

Please sign in to comment.