-
Notifications
You must be signed in to change notification settings - Fork 0
/
snapshots.go
58 lines (45 loc) · 1.51 KB
/
snapshots.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
package goarubacloud
const snapshotPath = "SetEnqueueServerSnapshot"
// SnapshotsService is an interface for interfacing with the cloud server actions
// endpoints of the Arubacloud API
type SnapshotsService interface {
Create(int) (*Response, error)
Restore(int) (*Response, error)
Delete(int) (*Response, error)
}
// SnapshotsServiceOp handles communication with the cloud server action related
// methods of the Arubacloud API.
type SnapshotsServiceOp struct {
client *Client
}
type snapshotRequest struct {
ServerId int
SnapshotOperationTypes string
}
var _ SnapshotsService = &SnapshotsServiceOp{}
func (s *SnapshotsServiceOp) Create(serverId int) (*Response, error) {
action := &snapshotRequest{ServerId: serverId, SnapshotOperationTypes: "Create"}
return s.doAction(action)
}
func (s *SnapshotsServiceOp) Restore(serverId int) (*Response, error) {
action := &snapshotRequest{ServerId: serverId, SnapshotOperationTypes: "Restore"}
return s.doAction(action)
}
func (s *SnapshotsServiceOp) Delete(serverId int) (*Response, error) {
action := &snapshotRequest{ServerId: serverId, SnapshotOperationTypes: "Delete"}
return s.doAction(action)
}
func (s *SnapshotsServiceOp) doAction(snapshotRequest *snapshotRequest) (*Response, error) {
data := struct {
Snapshot interface{} `json:"Snapshot"`
}{snapshotRequest}
req, err := s.client.NewRequest(snapshotPath, data)
if err != nil {
return nil, err
}
resp, err := s.client.Do(req, nil)
if err != nil {
return resp, err
}
return resp, err
}