-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use the tab renderer for "pool ls" and "pool volume ls" * Fix the PoolList not reporting the "shm" pool * Use a int64 to report pool usage and vol size in bytes * Add Pool and Size to instance.Config so "volume ls" doesn't have to go to disk to read this on every request * Add a path.Relations type to ease conversion to/from string slice
- Loading branch information
Showing
31 changed files
with
844 additions
and
571 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,53 @@ | ||
package commands | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/opensvc/om3/core/client" | ||
"github.com/opensvc/om3/core/clientcontext" | ||
"github.com/opensvc/om3/core/object" | ||
"github.com/opensvc/om3/core/output" | ||
"github.com/opensvc/om3/core/rawconfig" | ||
"github.com/opensvc/om3/daemon/api" | ||
) | ||
|
||
type ( | ||
CmdPoolLs struct { | ||
OptsGlobal | ||
Name string | ||
} | ||
) | ||
|
||
func (t *CmdPoolLs) Run() error { | ||
var ( | ||
data []string | ||
err error | ||
) | ||
if t.Local || !clientcontext.IsSet() { | ||
data, err = t.extractLocal() | ||
} else { | ||
data, err = t.extractDaemon() | ||
c, err := client.New(client.WithURL(t.Server)) | ||
if err != nil { | ||
return err | ||
} | ||
output.Renderer{ | ||
Output: t.Output, | ||
Color: t.Color, | ||
Data: data, | ||
HumanRenderer: func() string { | ||
s := "" | ||
for _, e := range data { | ||
s += e + "\n" | ||
} | ||
return s | ||
}, | ||
Colorize: rawconfig.Colorize, | ||
}.Print() | ||
return err | ||
} | ||
|
||
func (t *CmdPoolLs) extractLocal() ([]string, error) { | ||
n, err := object.NewNode() | ||
params := api.GetPoolParams{} | ||
if t.Name != "" { | ||
params.Name = &t.Name | ||
} | ||
resp, err := c.GetPoolWithResponse(context.Background(), ¶ms) | ||
if err != nil { | ||
return []string{}, err | ||
return err | ||
} | ||
return n.ListPools(), nil | ||
} | ||
|
||
func (t *CmdPoolLs) extractDaemon() ([]string, error) { | ||
var ( | ||
c *client.T | ||
err error | ||
) | ||
if c, err = client.New(client.WithURL(t.Server)); err != nil { | ||
return []string{}, err | ||
switch resp.StatusCode() { | ||
case 200: | ||
output.Renderer{ | ||
DefaultOutput: "tab=NAME:name,TYPE:type,CAPABILITIES:capabilities[*],HEAD:head,SIZE:size,USED:used,FREE:free", | ||
Output: t.Output, | ||
Color: t.Color, | ||
Data: *resp.JSON200, | ||
Colorize: rawconfig.Colorize, | ||
}.Print() | ||
return nil | ||
case 401: | ||
return fmt.Errorf("%s", resp.JSON401) | ||
case 403: | ||
return fmt.Errorf("%s", resp.JSON403) | ||
case 500: | ||
return fmt.Errorf("%s", resp.JSON500) | ||
default: | ||
return fmt.Errorf("unexpected status code: %d", resp.StatusCode()) | ||
} | ||
return []string{}, fmt.Errorf("todo %v", c) | ||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package commands | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/opensvc/om3/core/client" | ||
"github.com/opensvc/om3/core/output" | ||
"github.com/opensvc/om3/core/rawconfig" | ||
"github.com/opensvc/om3/daemon/api" | ||
) | ||
|
||
type ( | ||
CmdPoolVolumeLs struct { | ||
OptsGlobal | ||
Name string | ||
} | ||
) | ||
|
||
func (t *CmdPoolVolumeLs) Run() error { | ||
c, err := client.New(client.WithURL(t.Server)) | ||
if err != nil { | ||
return err | ||
} | ||
params := api.GetPoolVolumeParams{} | ||
if t.Name != "" { | ||
params.Name = &t.Name | ||
} | ||
resp, err := c.GetPoolVolumeWithResponse(context.Background(), ¶ms) | ||
if err != nil { | ||
return err | ||
} | ||
switch resp.StatusCode() { | ||
case 200: | ||
output.Renderer{ | ||
DefaultOutput: "tab=POOL:pool,PATH:path,SIZE:size,CHILDREN:children[*],IS_ORPHAN:is_orphan", | ||
Output: t.Output, | ||
Color: t.Color, | ||
Data: *resp.JSON200, | ||
Colorize: rawconfig.Colorize, | ||
}.Print() | ||
return nil | ||
case 401: | ||
return fmt.Errorf("%s", resp.JSON401) | ||
case 403: | ||
return fmt.Errorf("%s", resp.JSON403) | ||
case 500: | ||
return fmt.Errorf("%s", resp.JSON500) | ||
default: | ||
return fmt.Errorf("unexpected status code: %d", resp.StatusCode()) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.