-
Notifications
You must be signed in to change notification settings - Fork 7
/
results.go
74 lines (64 loc) · 2.35 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
package volumetypes
import (
"github.com/huaweicloud/terraform-provider-hcs/huaweicloudstack/sdk/huaweicloud"
"github.com/huaweicloud/terraform-provider-hcs/huaweicloudstack/sdk/huaweicloud/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"`
}
// 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) {
volumetypes, err := ExtractVolumeTypes(r)
return len(volumetypes) == 0, err
}
// NextPageURL uses the response's embedded link reference to navigate to the
// next page of results.
func (page VolumeTypePage) NextPageURL() (string, error) {
var s struct {
Links []golangsdk.Link `json:"volume_type_links"`
}
err := page.ExtractInto(&s)
if err != nil {
return "", err
}
return golangsdk.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 {
golangsdk.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")
}