-
Notifications
You must be signed in to change notification settings - Fork 19
/
blockstorage_snapshot_show.go
86 lines (69 loc) · 2.6 KB
/
blockstorage_snapshot_show.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
package cmd
import (
"fmt"
"strings"
"time"
"github.com/spf13/cobra"
"github.com/exoscale/cli/pkg/globalstate"
"github.com/exoscale/cli/pkg/output"
v3 "github.com/exoscale/egoscale/v3"
)
type blockStorageSnapshotShowOutput struct {
CreatedAT time.Time `json:"created-at"`
ID v3.UUID `json:"id"`
Volume *v3.BlockStorageVolumeTarget `json:"volume"`
Name string `json:"name"`
Size string `json:"size"`
State v3.BlockStorageSnapshotState `json:"state"`
Labels map[string]string `json:"labels"`
}
func (o *blockStorageSnapshotShowOutput) Type() string { return "Block Storage Volume Snapshot" }
func (o *blockStorageSnapshotShowOutput) ToJSON() { output.JSON(o) }
func (o *blockStorageSnapshotShowOutput) ToText() { output.Text(o) }
func (o *blockStorageSnapshotShowOutput) ToTable() { output.Table(o) }
type blockStorageSnapshotShowCmd struct {
cliCommandSettings `cli-cmd:"-"`
_ bool `cli-cmd:"show"`
Name string `cli-arg:"#" cli-usage:"NAME|ID"`
Zone v3.ZoneName `cli-short:"z" cli-usage:"block storage zone"`
}
func (c *blockStorageSnapshotShowCmd) cmdAliases() []string { return gShowAlias }
func (c *blockStorageSnapshotShowCmd) cmdShort() string { return "Show a Block Storage Volume details" }
func (c *blockStorageSnapshotShowCmd) cmdLong() string {
return fmt.Sprintf(`This command shows a Block Storage Volume Snapshot details.
Supported output template annotations: %s`,
strings.Join(output.TemplateAnnotations(&instanceShowOutput{}), ", "))
}
func (c *blockStorageSnapshotShowCmd) cmdPreRun(cmd *cobra.Command, args []string) error {
cmdSetZoneFlagFromDefault(cmd)
return cliCommandDefaultPreRun(c, cmd, args)
}
func (c *blockStorageSnapshotShowCmd) cmdRun(cmd *cobra.Command, _ []string) error {
ctx := gContext
client, err := switchClientZoneV3(ctx, globalstate.EgoscaleV3Client, c.Zone)
if err != nil {
return err
}
snapshots, err := client.ListBlockStorageSnapshots(ctx)
if err != nil {
return err
}
snapshot, err := snapshots.FindBlockStorageSnapshot(c.Name)
if err != nil {
return err
}
return c.outputFunc(&blockStorageSnapshotShowOutput{
ID: snapshot.ID,
Name: snapshot.Name,
Size: fmt.Sprintf("%d GiB", snapshot.Size),
CreatedAT: snapshot.CreatedAT,
State: snapshot.State,
Volume: snapshot.BlockStorageVolume,
Labels: snapshot.Labels,
}, nil)
}
func init() {
cobra.CheckErr(registerCLICommand(blockstorageSnapshotCmd, &blockStorageSnapshotShowCmd{
cliCommandSettings: defaultCLICmdSettings(),
}))
}