-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.go
156 lines (132 loc) · 3.46 KB
/
image.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package vmmanagerapi
import (
"encoding/json"
"fmt"
"github.com/gadost/go-vmmanager-api/types"
)
// ImageNew create new image
func (a *Api) ImageNew(hid int, params *types.Image) (*types.Task, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/host/%d/image/create", hid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// Images return images
func (a *Api) Images() (*types.ImagesListResponse, error) {
bodyResp, err := a.NewRequest(
NilPayload,
"/image",
requestTypeGet,
DefaultService)
var h *types.ImagesListResponse
json.Unmarshal(bodyResp, &h)
return h, err
}
// Image return image params
func (a *Api) Image(imid int) (*types.ImageResponse, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/image/%d", imid),
requestTypeGet,
DefaultService)
var h *types.ImageResponse
json.Unmarshal(bodyResp, &h)
return h, err
}
// ImageUpdate update image params
func (a *Api) ImageUpdate(imid int, params *types.Image) (*types.Task, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/image/%d", imid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// ImageDelete delete image
func (a *Api) ImageDelete(hid int) (*types.Task, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/image/%d", hid),
requestTypeDelete,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// ImageStateUpdate update image state
func (a *Api) ImageStateUpdate(imid int, params *types.ImageState) (*types.Task, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/image/%d/change_state", imid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// ImageCopy copy image
func (a *Api) ImageCopy(imid int, params *types.Node) (*types.Task, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/image/%d/copy", imid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// ImageMove move image
func (a *Api) ImageMove(imid int, params *types.Move) (*types.Task, error) {
payload, _ := json.Marshal(params)
bodyResp, err := a.NewRequest(
payload,
fmt.Sprintf("/image/%d/move", imid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// ImageNodeDelete delete image on node
func (a *Api) ImageNodeDelete(imid int, nid int) (*types.Task, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/image/%d/node/%d", imid, nid),
requestTypeDelete,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// ImageNodeEnable enable image on node
func (a *Api) ImageNodeEnable(imid int, nid int) (*types.Task, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/image/%d/node/%d/enable", imid, nid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}
// ImageNodeDisable disable image on node
func (a *Api) ImageNodeDisable(imid int, nid int) (*types.Task, error) {
bodyResp, err := a.NewRequest(
NilPayload,
fmt.Sprintf("/image/%d/node/%d/disable", imid, nid),
requestTypePost,
DefaultService)
var t *types.Task
json.Unmarshal(bodyResp, &t)
return t, err
}