-
Notifications
You must be signed in to change notification settings - Fork 0
/
storages.go
95 lines (75 loc) · 2.71 KB
/
storages.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
package vmmanagerapi
import (
"encoding/json"
"fmt"
"github.com/gadost/go-vmmanager-api/types"
)
// Storages returns all storages
func (a *Api) Storages() (*types.Storages, error) {
bodyResp, err := a.NewRequest(NilPayload, "/storage", requestTypeGet, DefaultService)
var r *types.Storages
json.Unmarshal(bodyResp, &r)
return r, err
}
// Storage returns storage params
func (a *Api) Storage(sid int) (*types.StorageParams, error) {
uri := fmt.Sprintf("/storage/%d", sid)
bodyResp, err := a.NewRequest(NilPayload, uri, requestTypeGet, DefaultService)
var r *types.StorageParams
json.Unmarshal(bodyResp, &r)
return r, err
}
// StorageNode return node storage params
func (a *Api) StorageNode(sid int) ([]byte, error) {
uri := fmt.Sprintf("/storage/%d/node", sid)
bodyResp, err := a.NewRequest(NilPayload, uri, requestTypeGet, DefaultService)
return bodyResp, err
}
// StorageLocal return local storage params
func (a *Api) StorageLocal() ([]byte, error) {
bodyResp, err := a.NewRequest(NilPayload, "/storage/local", requestTypeGet, DefaultService)
return bodyResp, err
}
// StorageNew create new storage
func (a *Api) StorageNew(params *types.StorageNew) (*types.ID, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(payload, "/storage", requestTypePost, DefaultService)
var r *types.ID
json.Unmarshal(bodyResp, &r)
return r, err
}
// StorageUpdate update storage params
func (a *Api) StorageUpdate(sid int, params *types.StorageUpdate) (*types.ID, error) {
payload, _ := json.Marshal(params)
uri := fmt.Sprintf("/storage/%d", sid)
bodyResp, err := a.NewRequest(payload, uri, requestTypePost, DefaultService)
var r *types.ID
json.Unmarshal(bodyResp, &r)
return r, err
}
// StorageStateUpdate update storage state
func (a *Api) StorageStateUpdate(sid int, params *types.State) (*types.ID, error) {
payload, _ := json.Marshal(params)
uri := fmt.Sprintf("/storage/%d/change_state", sid)
bodyResp, err := a.NewRequest(payload, uri, requestTypePost, DefaultService)
var r *types.ID
json.Unmarshal(bodyResp, &r)
return r, err
}
// update node storage state
func (a *Api) NodeStorageStateUpdate(sid int, nid int, params *types.State) (*types.ID, error) {
payload, _ := json.Marshal(params)
uri := fmt.Sprintf("/storage/%d/node/%d/change_state", sid, nid)
bodyResp, err := a.NewRequest(payload, uri, requestTypePost, DefaultService)
var r *types.ID
json.Unmarshal(bodyResp, &r)
return r, err
}
// StorageDelete delete storage
func (a *Api) StorageDelete(sid int) (*types.DeletedResponse, error) {
uri := fmt.Sprintf("/storage/%d", sid)
bodyResp, err := a.NewRequest(NilPayload, uri, requestTypeDelete, DefaultService)
var r *types.DeletedResponse
json.Unmarshal(bodyResp, &r)
return r, err
}