forked from rancher/convoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
snapshot.go
110 lines (92 loc) · 2.14 KB
/
snapshot.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package client
import (
"github.com/codegangsta/cli"
"github.com/rancher/convoy/api"
"github.com/rancher/convoy/util"
)
var (
snapshotCreateCmd = cli.Command{
Name: "create",
Usage: "create a snapshot for certain volume: snapshot create <volume>",
Flags: []cli.Flag{
cli.StringFlag{
Name: "name",
Usage: "name of snapshot",
},
},
Action: cmdSnapshotCreate,
}
snapshotDeleteCmd = cli.Command{
Name: "delete",
Usage: "delete a snapshot: snapshot delete <snapshot>",
Action: cmdSnapshotDelete,
}
snapshotInspectCmd = cli.Command{
Name: "inspect",
Usage: "inspect an snapshot: snapshot inspect <snapshot>",
Action: cmdSnapshotInspect,
}
snapshotCmd = cli.Command{
Name: "snapshot",
Usage: "snapshot related operations",
Subcommands: []cli.Command{
snapshotCreateCmd,
snapshotDeleteCmd,
snapshotInspectCmd,
},
}
)
func cmdSnapshotCreate(c *cli.Context) {
if err := doSnapshotCreate(c); err != nil {
panic(err)
}
}
func doSnapshotCreate(c *cli.Context) error {
var err error
volumeUUID, err := getOrRequestUUID(c, "", true)
snapshotName, err := util.GetName(c, "name", false, err)
if err != nil {
return err
}
request := &api.SnapshotCreateRequest{
Name: snapshotName,
VolumeUUID: volumeUUID,
Verbose: c.GlobalBool(verboseFlag),
}
url := "/snapshots/create"
return sendRequestAndPrint("POST", url, request)
}
func cmdSnapshotDelete(c *cli.Context) {
if err := doSnapshotDelete(c); err != nil {
panic(err)
}
}
func doSnapshotDelete(c *cli.Context) error {
var err error
uuid, err := getOrRequestUUID(c, "", true)
if err != nil {
return err
}
request := &api.SnapshotDeleteRequest{
SnapshotUUID: uuid,
}
url := "/snapshots/"
return sendRequestAndPrint("DELETE", url, request)
}
func cmdSnapshotInspect(c *cli.Context) {
if err := doSnapshotInspect(c); err != nil {
panic(err)
}
}
func doSnapshotInspect(c *cli.Context) error {
var err error
uuid, err := getOrRequestUUID(c, "", true)
if err != nil {
return err
}
request := &api.SnapshotInspectRequest{
SnapshotUUID: uuid,
}
url := "/snapshots/"
return sendRequestAndPrint("GET", url, request)
}