forked from askholme/vultr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnapshot.go
69 lines (66 loc) · 1.85 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
package vultr
import (
"fmt"
)
type Snapshot struct {
Id string `json:"SNAPSHOTID"`
Created string `json:"date_created"`
Description string `json:"description"`
Size string `json:"size"`
Status string `json:"status"`
}
func (c *Client) CreateSnapshot(serverId string, description string) (string, error) {
params := make(map[string]string)
params["SUBID"] = serverId
params["description"] = description
data := make(map[string]string)
err := c.RequestInterface(params, "/snapshot/create", "POST", &data)
if err != nil {
return "", err
}
return data["SNAPSHOTID"], err
}
func (c *Client) DeleteSnapshot(snapshotId string) error {
params := make(map[string]string)
params["SUBID"] = snapshotId
_, err := c.RequestStr(params, "/snapshot/destroy", "POST")
return err
}
func (c *Client) GetSnapshots() (map[string]Snapshot, error) {
snapshotlist := make(map[string]Snapshot)
err := c.RequestInterface(nil, "/snapshot/list", "GET", &snapshotlist)
if err != nil {
return snapshotlist, err
}
return snapshotlist, nil
}
func (c *Client) GetSnapshot(snapshotId string) (*Snapshot, error) {
serverlist, err := c.GetSnapshots()
if err != nil {
return nil, err
}
//var s Server
for id, snapshot := range serverlist {
if id == snapshotId {
debug("%s did match in snapshot list", id)
return &snapshot, nil
}
debug("%s did not match in snapshot list", id)
}
return nil, fmt.Errorf("Snapshot not found")
}
func (c *Client) GetSnapshotByLabel(snapshotLabel string) (*Snapshot, error) {
serverlist, err := c.GetSnapshots()
if err != nil {
return nil, err
}
//var s Server
for id, snapshot := range serverlist {
if snapshot.Description == snapshotLabel {
debug("%s did match in snapshot list", id)
return &snapshot, nil
}
debug("%s did not match in snapshot list", id)
}
return nil, fmt.Errorf("Snapshot not found")
}