-
Notifications
You must be signed in to change notification settings - Fork 6
/
pool_volume_ls.go
52 lines (48 loc) · 1.09 KB
/
pool_volume_ls.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package omcmd
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.GetPoolVolumesParams{}
if t.Name != "" {
params.Name = &t.Name
}
resp, err := c.GetPoolVolumesWithResponse(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())
}
}