-
Notifications
You must be signed in to change notification settings - Fork 241
/
volumes.go
82 lines (62 loc) · 1.65 KB
/
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
package volumes
import (
"bytes"
"context"
"fmt"
"io"
"time"
"github.com/spf13/cobra"
"github.com/superfly/flyctl/api"
"github.com/superfly/flyctl/client"
"github.com/superfly/flyctl/internal/command"
"github.com/superfly/flyctl/internal/command/volumes/snapshots"
)
func New() *cobra.Command {
const (
long = "Commands for managing Fly Volumes associated with an application"
short = "Volume management commands"
usage = "volumes <command>"
)
cmd := command.New(usage, short, long, nil)
cmd.Aliases = []string{"volume", "vol"}
cmd.AddCommand(
newCreate(),
newList(),
newDestroy(),
newExtend(),
newShow(),
newFork(),
snapshots.New(),
)
return cmd
}
func printVolume(w io.Writer, vol *api.Volume) error {
var buf bytes.Buffer
fmt.Fprintf(&buf, "%10s: %s\n", "ID", vol.ID)
fmt.Fprintf(&buf, "%10s: %s\n", "Name", vol.Name)
fmt.Fprintf(&buf, "%10s: %s\n", "App", vol.App.Name)
fmt.Fprintf(&buf, "%10s: %s\n", "Region", vol.Region)
fmt.Fprintf(&buf, "%10s: %s\n", "Zone", vol.Host.ID)
fmt.Fprintf(&buf, "%10s: %d\n", "Size GB", vol.SizeGb)
fmt.Fprintf(&buf, "%10s: %t\n", "Encrypted", vol.Encrypted)
fmt.Fprintf(&buf, "%10s: %s\n", "Created at", vol.CreatedAt.Format(time.RFC822))
_, err := buf.WriteTo(w)
return err
}
func countVolumesMatchingName(ctx context.Context, appName string, volumeName string) (int32, error) {
var (
volumes []api.Volume
err error
client = client.FromContext(ctx).API()
)
if volumes, err = client.GetVolumes(ctx, appName); err != nil {
return 0, err
}
var matches int32
for _, volume := range volumes {
if volume.Name == volumeName {
matches++
}
}
return matches, nil
}