-
Notifications
You must be signed in to change notification settings - Fork 72
/
controller_list_volumes.go
94 lines (79 loc) · 1.83 KB
/
controller_list_volumes.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package cmd
import (
"context"
"os"
"github.com/spf13/cobra"
"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/rexray/gocsi/utils"
)
var listVolumes struct {
maxEntries int32
startingToken string
paging bool
}
var listVolumesCmd = &cobra.Command{
Use: "list-volumes",
Aliases: []string{"ls", "list", "volumes"},
Short: `invokes the rpc "ListVolumes"`,
RunE: func(*cobra.Command, []string) error {
ctx, cancel := context.WithTimeout(root.ctx, root.timeout)
defer cancel()
req := csi.ListVolumesRequest{
MaxEntries: listVolumes.maxEntries,
StartingToken: listVolumes.startingToken,
}
// If auto-paging is not enabled then send a normal request.
if !listVolumes.paging {
rep, err := controller.client.ListVolumes(ctx, &req)
if err != nil {
return err
}
return root.tpl.Execute(os.Stdout, rep)
}
// Paging is enabled.
cvol, cerr := utils.PageVolumes(ctx, controller.client, req)
for {
select {
case v, ok := <-cvol:
if !ok {
return nil
}
if err := root.tpl.Execute(os.Stdout, v); err != nil {
return err
}
case e, ok := <-cerr:
if !ok {
return nil
}
return e
}
}
},
}
func init() {
controllerCmd.AddCommand(listVolumesCmd)
listVolumesCmd.Flags().Int32Var(
&listVolumes.maxEntries,
"max-entries",
0,
"The maximum number of entries to return")
listVolumesCmd.Flags().StringVar(
&listVolumes.startingToken,
"starting-token",
"",
"The starting token used to retrieve paged data")
listVolumesCmd.Flags().BoolVar(
&listVolumes.paging,
"paging",
false,
"Enables auto-paging")
listVolumesCmd.Flags().StringVar(
&root.format,
"format",
"",
"The Go template format used to emit the results")
flagWithRequiresAttribs(
listVolumesCmd.Flags(),
&root.withRequiresVolumeAttributes,
"")
}