This repository has been archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 34
/
results.go
156 lines (138 loc) · 4.41 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
package shares
import (
"encoding/json"
"time"
"github.com/huaweicloud/golangsdk"
"github.com/huaweicloud/golangsdk/pagination"
)
// TurboResponse contains the information of creating response
type TurboResponse struct {
ID string `json:"id"`
Name string `json:"name"`
Status string `json:"status"`
}
// Turbo contains all information associated with an SFS Turbo file system
type Turbo struct {
// The UUID of the SFS Turbo file system
ID string `json:"id"`
// The name of the SFS Turbo file system
Name string `json:"name"`
// Size of the share in GB
Size string `json:"size"`
// The statue of the SFS Turbo file system
Status string `json:"status"`
// The sub-statue of the SFS Turbo file system
SubStatus string `json:"sub_status"`
// The version ID of the SFS Turbo file system
Version string `json:"version"`
// The mount location
ExportLocation string `json:"export_location"`
// The creation progress of the SFS Turbo file system
Actions []string `json:"actions"`
// The protocol type of the SFS Turbo file system
ShareProto string `json:"share_proto"`
// The type of the SFS Turbo file system, STANDARD or PERFORMANCE.
ShareType string `json:"share_type"`
// The region of the SFS Turbo file system
Region string `json:"region"`
// The code of the availability zone
AvailabilityZone string `json:"availability_zone"`
// The name of the availability zone
AZName string `json:"az_name"`
// The VPC ID
VpcID string `json:"vpc_id"`
// The subnet ID
SubnetID string `json:"subnet_id"`
// The security group ID
SecurityGroupID string `json:"security_group_id"`
// The avaliable capacity if the SFS Turbo file system
AvailCapacity string `json:"avail_capacity"`
// bandwidth is returned for an enhanced file system
ExpandType string `json:"expand_type"`
// The ID of the encryption key
CryptKeyID string `json:"crypt_key_id"`
// The billing mode, 0 indicates pay-per-use, 1 indicates yearly/monthly subscription
PayModel string `json:"pay_model"`
// Timestamp when the share was created
CreatedAt time.Time `json:"-"`
// The enterprise project ID
EnterpriseProjectId string `json:"enterprise_project_id"`
}
func (r *Turbo) UnmarshalJSON(b []byte) error {
type tmp Turbo
var s struct {
tmp
CreatedAt golangsdk.JSONRFC3339MilliNoZ `json:"created_at"`
}
err := json.Unmarshal(b, &s)
if err != nil {
return err
}
*r = Turbo(s.tmp)
r.CreatedAt = time.Time(s.CreatedAt)
return nil
}
type commonResult struct {
golangsdk.Result
}
// CreateResult contains the response body and error from a Create request.
type CreateResult struct {
commonResult
}
// GetResult contains the response body and error from a Get request.
type GetResult struct {
commonResult
}
// DeleteResult contains the response body and error from a Delete request.
type DeleteResult struct {
golangsdk.ErrResult
}
// ExpandResult contains the response body and error from a Expand request.
type ExpandResult struct {
golangsdk.ErrResult
}
// Extract will get the Turbo response object from the CreateResult
func (r CreateResult) Extract() (*TurboResponse, error) {
var resp TurboResponse
err := r.ExtractInto(&resp)
return &resp, err
}
// Extract will get the Turbo object from the GetResult
func (r GetResult) Extract() (*Turbo, error) {
var object Turbo
err := r.ExtractInto(&object)
return &object, err
}
// TurboPage is the page returned by a pager when traversing over a
// collection of Shares.
type TurboPage struct {
pagination.LinkedPageBase
}
// ExtractTurbos accepts a Page struct, specifically a TurboPage struct,
// and extracts the elements into a slice of share structs. In other words,
// a generic collection is mapped into a relevant slice.
func ExtractTurbos(r pagination.Page) ([]Turbo, error) {
var s struct {
ListedShares []Turbo `json:"shares"`
}
err := (r.(TurboPage)).ExtractInto(&s)
return s.ListedShares, err
}
// IsEmpty returns true if a ListResult contains no Shares.
func (r TurboPage) IsEmpty() (bool, error) {
shares, err := ExtractTurbos(r)
return len(shares) == 0, err
}
// NextPageURL is invoked when a paginated collection of shares has reached
// the end of a page and the pager seeks to traverse over a new one. In order
// to do this, it needs to construct the next page's URL.
func (r TurboPage) NextPageURL() (string, error) {
var s struct {
Links []golangsdk.Link `json:"shares_links"`
}
err := r.ExtractInto(&s)
if err != nil {
return "", err
}
return golangsdk.ExtractNextURL(s.Links)
}