-
Notifications
You must be signed in to change notification settings - Fork 515
/
results.go
299 lines (253 loc) · 8.63 KB
/
results.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
package volumetypes
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// VolumeType contains all the information associated with an OpenStack Volume Type.
type VolumeType struct {
// Unique identifier for the volume type.
ID string `json:"id"`
// Human-readable display name for the volume type.
Name string `json:"name"`
// Human-readable description for the volume type.
Description string `json:"description"`
// Arbitrary key-value pairs defined by the user.
ExtraSpecs map[string]string `json:"extra_specs"`
// Whether the volume type is publicly visible.
IsPublic bool `json:"is_public"`
// Qos Spec ID
QosSpecID string `json:"qos_specs_id"`
// Volume Type access public attribute
PublicAccess bool `json:"os-volume-type-access:is_public"`
}
// VolumeTypePage is a pagination.pager that is returned from a call to the List function.
type VolumeTypePage struct {
pagination.LinkedPageBase
}
// IsEmpty returns true if a ListResult contains no Volume Types.
func (r VolumeTypePage) IsEmpty() (bool, error) {
if r.StatusCode == 204 {
return true, nil
}
volumetypes, err := ExtractVolumeTypes(r)
return len(volumetypes) == 0, err
}
func (page VolumeTypePage) NextPageURL() (string, error) {
var s struct {
Links []gophercloud.Link `json:"volume_type_links"`
}
err := page.ExtractInto(&s)
if err != nil {
return "", err
}
return gophercloud.ExtractNextURL(s.Links)
}
// ExtractVolumeTypes extracts and returns Volumes. It is used while iterating over a volumetypes.List call.
func ExtractVolumeTypes(r pagination.Page) ([]VolumeType, error) {
var s []VolumeType
err := ExtractVolumeTypesInto(r, &s)
return s, err
}
type commonResult struct {
gophercloud.Result
}
// Extract will get the Volume Type object out of the commonResult object.
func (r commonResult) Extract() (*VolumeType, error) {
var s VolumeType
err := r.ExtractInto(&s)
return &s, err
}
// ExtractInto converts our response data into a volume type struct
func (r commonResult) ExtractInto(v interface{}) error {
return r.Result.ExtractIntoStructPtr(v, "volume_type")
}
// ExtractVolumeTypesInto similar to ExtractInto but operates on a `list` of volume types
func ExtractVolumeTypesInto(r pagination.Page, v interface{}) error {
return r.(VolumeTypePage).Result.ExtractIntoSlicePtr(v, "volume_types")
}
// GetResult contains the response body and error from a Get request.
type GetResult struct {
commonResult
}
// CreateResult contains the response body and error from a Create request.
type CreateResult struct {
commonResult
}
// DeleteResult contains the response body and error from a Delete request.
type DeleteResult struct {
gophercloud.ErrResult
}
// UpdateResult contains the response body and error from an Update request.
type UpdateResult struct {
commonResult
}
// extraSpecsResult contains the result of a call for (potentially) multiple
// key-value pairs. Call its Extract method to interpret it as a
// map[string]interface.
type extraSpecsResult struct {
gophercloud.Result
}
// ListExtraSpecsResult contains the result of a Get operation. Call its Extract
// method to interpret it as a map[string]interface.
type ListExtraSpecsResult struct {
extraSpecsResult
}
// CreateExtraSpecsResult contains the result of a Create operation. Call its
// Extract method to interpret it as a map[string]interface.
type CreateExtraSpecsResult struct {
extraSpecsResult
}
// Extract interprets any extraSpecsResult as ExtraSpecs, if possible.
func (r extraSpecsResult) Extract() (map[string]string, error) {
var s struct {
ExtraSpecs map[string]string `json:"extra_specs"`
}
err := r.ExtractInto(&s)
return s.ExtraSpecs, err
}
// extraSpecResult contains the result of a call for individual a single
// key-value pair.
type extraSpecResult struct {
gophercloud.Result
}
// GetExtraSpecResult contains the result of a Get operation. Call its Extract
// method to interpret it as a map[string]interface.
type GetExtraSpecResult struct {
extraSpecResult
}
// UpdateExtraSpecResult contains the result of an Update operation. Call its
// Extract method to interpret it as a map[string]interface.
type UpdateExtraSpecResult struct {
extraSpecResult
}
// DeleteExtraSpecResult contains the result of a Delete operation. Call its
// ExtractErr method to determine if the call succeeded or failed.
type DeleteExtraSpecResult struct {
gophercloud.ErrResult
}
// Extract interprets any extraSpecResult as an ExtraSpec, if possible.
func (r extraSpecResult) Extract() (map[string]string, error) {
var s map[string]string
err := r.ExtractInto(&s)
return s, err
}
// VolumeTypeAccess represents an ACL of project access to a specific Volume Type.
type VolumeTypeAccess struct {
// VolumeTypeID is the unique ID of the volume type.
VolumeTypeID string `json:"volume_type_id"`
// ProjectID is the unique ID of the project.
ProjectID string `json:"project_id"`
}
// AccessPage contains a single page of all VolumeTypeAccess entries for a volume type.
type AccessPage struct {
pagination.SinglePageBase
}
// IsEmpty indicates whether an AccessPage is empty.
func (page AccessPage) IsEmpty() (bool, error) {
if page.StatusCode == 204 {
return true, nil
}
v, err := ExtractAccesses(page)
return len(v) == 0, err
}
// ExtractAccesses interprets a page of results as a slice of VolumeTypeAccess.
func ExtractAccesses(r pagination.Page) ([]VolumeTypeAccess, error) {
var s struct {
VolumeTypeAccesses []VolumeTypeAccess `json:"volume_type_access"`
}
err := (r.(AccessPage)).ExtractInto(&s)
return s.VolumeTypeAccesses, err
}
// AddAccessResult is the response from a AddAccess request. Call its
// ExtractErr method to determine if the request succeeded or failed.
type AddAccessResult struct {
gophercloud.ErrResult
}
// RemoveAccessResult is the response from a RemoveAccess request. Call its
// ExtractErr method to determine if the request succeeded or failed.
type RemoveAccessResult struct {
gophercloud.ErrResult
}
type EncryptionType struct {
// Unique identifier for the volume type.
VolumeTypeID string `json:"volume_type_id"`
// Notional service where encryption is performed.
ControlLocation string `json:"control_location"`
// Unique identifier for encryption type.
EncryptionID string `json:"encryption_id"`
// Size of encryption key.
KeySize int `json:"key_size"`
// Class that provides encryption support.
Provider string `json:"provider"`
// The encryption algorithm or mode.
Cipher string `json:"cipher"`
}
type encryptionResult struct {
gophercloud.Result
}
func (r encryptionResult) Extract() (*EncryptionType, error) {
var s EncryptionType
err := r.ExtractInto(&s)
return &s, err
}
// ExtractInto converts our response data into a volume type struct
func (r encryptionResult) ExtractInto(v interface{}) error {
return r.Result.ExtractIntoStructPtr(v, "encryption")
}
type CreateEncryptionResult struct {
encryptionResult
}
// UpdateResult contains the response body and error from an UpdateEncryption request.
type UpdateEncryptionResult struct {
encryptionResult
}
// DeleteEncryptionResult contains the response body and error from a DeleteEncryprion request.
type DeleteEncryptionResult struct {
gophercloud.ErrResult
}
type GetEncryptionType struct {
// Unique identifier for the volume type.
VolumeTypeID string `json:"volume_type_id"`
// Notional service where encryption is performed.
ControlLocation string `json:"control_location"`
// Shows if the resource is deleted or Notional
Deleted bool `json:"deleted"`
// Shows the date and time the resource was created.
CreatedAt string `json:"created_at"`
// Shows the date and time when resource was updated.
UpdatedAt string `json:"updated_at"`
// Unique identifier for encryption type.
EncryptionID string `json:"encryption_id"`
// Size of encryption key.
KeySize int `json:"key_size"`
// Class that provides encryption support.
Provider string `json:"provider"`
// Shows the date and time the reousrce was deleted.
DeletedAt string `json:"deleted_at"`
// The encryption algorithm or mode.
Cipher string `json:"cipher"`
}
type encryptionShowResult struct {
gophercloud.Result
}
// Extract interprets any extraSpecResult as an ExtraSpec, if possible.
func (r encryptionShowResult) Extract() (*GetEncryptionType, error) {
var s GetEncryptionType
err := r.ExtractInto(&s)
return &s, err
}
type GetEncryptionResult struct {
encryptionShowResult
}
type encryptionShowSpecResult struct {
gophercloud.Result
}
// Extract interprets any empty interface Result as an empty interface.
func (r encryptionShowSpecResult) Extract() (map[string]interface{}, error) {
var s map[string]interface{}
err := r.ExtractInto(&s)
return s, err
}
type GetEncryptionSpecResult struct {
encryptionShowSpecResult
}