-
Notifications
You must be signed in to change notification settings - Fork 0
/
results.go
293 lines (227 loc) · 9.43 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
package quotasets
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// QuotaSet is a set of operational limits that allow for control of compute
// usage.
type QuotaSet struct {
// ID is tenant associated with this QuotaSet.
ID string `json:"id"`
// FixedIPs is number of fixed ips alloted this QuotaSet.
FixedIPs int `json:"fixed_ips"`
// FloatingIPs is number of floating ips alloted this QuotaSet.
FloatingIPs int `json:"floating_ips"`
// InjectedFileContentBytes is the allowed bytes for each injected file.
InjectedFileContentBytes int `json:"injected_file_content_bytes"`
// InjectedFilePathBytes is allowed bytes for each injected file path.
InjectedFilePathBytes int `json:"injected_file_path_bytes"`
// InjectedFiles is the number of injected files allowed for each project.
InjectedFiles int `json:"injected_files"`
// KeyPairs is number of ssh keypairs.
KeyPairs int `json:"key_pairs"`
// MetadataItems is number of metadata items allowed for each instance.
MetadataItems int `json:"metadata_items"`
// RAM is megabytes allowed for each instance.
RAM int `json:"ram"`
// SecurityGroupRules is number of security group rules allowed for each
// security group.
SecurityGroupRules int `json:"security_group_rules"`
// SecurityGroups is the number of security groups allowed for each project.
SecurityGroups int `json:"security_groups"`
// Cores is number of instance cores allowed for each project.
Cores int `json:"cores"`
// Instances is number of instances allowed for each project.
Instances int `json:"instances"`
// ServerGroups is the number of ServerGroups allowed for the project.
ServerGroups int `json:"server_groups"`
// ServerGroupMembers is the number of members for each ServerGroup.
ServerGroupMembers int `json:"server_group_members"`
}
//QuotaDetailSet represents details of both operational limits of compute
//resources and the current usage of those resources.
type QuotaDetailSet struct {
// ID is the tenant ID associated with this QuotaDetailSet.
ID string `json:"id"`
// FixedIPs is number of fixed ips alloted this QuotaDetailSet.
FixedIPs QuotaDetail `json:"fixed_ips"`
// FloatingIPs is number of floating ips alloted this QuotaDetailSet.
FloatingIPs QuotaDetail `json:"floating_ips"`
// InjectedFileContentBytes is the allowed bytes for each injected file.
InjectedFileContentBytes QuotaDetail `json:"injected_file_content_bytes"`
// InjectedFilePathBytes is allowed bytes for each injected file path.
InjectedFilePathBytes QuotaDetail `json:"injected_file_path_bytes"`
// InjectedFiles is the number of injected files allowed for each project.
InjectedFiles QuotaDetail `json:"injected_files"`
// KeyPairs is number of ssh keypairs.
KeyPairs QuotaDetail `json:"key_pairs"`
// MetadataItems is number of metadata items allowed for each instance.
MetadataItems QuotaDetail `json:"metadata_items"`
// RAM is megabytes allowed for each instance.
RAM QuotaDetail `json:"ram"`
// SecurityGroupRules is number of security group rules allowed for each
// security group.
SecurityGroupRules QuotaDetail `json:"security_group_rules"`
// SecurityGroups is the number of security groups allowed for each project.
SecurityGroups QuotaDetail `json:"security_groups"`
// Cores is number of instance cores allowed for each project.
Cores QuotaDetail `json:"cores"`
// Instances is number of instances allowed for each project.
Instances QuotaDetail `json:"instances"`
// ServerGroups is the number of ServerGroups allowed for the project.
ServerGroups QuotaDetail `json:"server_groups"`
// ServerGroupMembers is the number of members for each ServerGroup.
ServerGroupMembers QuotaDetail `json:"server_group_members"`
}
type QuotaDefaultSet struct {
// ID is the tenant ID associated with this QuotaDetailSet.
ID string `json:"id"`
// FixedIPs is number of fixed ips alloted this QuotaDetailSet.
FixedIPs QuotaDetail `json:"fixed_ips"`
// FloatingIPs is number of floating ips alloted this QuotaDetailSet.
FloatingIPs QuotaDetail `json:"floating_ips"`
// InjectedFileContentBytes is the allowed bytes for each injected file.
InjectedFileContentBytes QuotaDetail `json:"injected_file_content_bytes"`
// InjectedFilePathBytes is allowed bytes for each injected file path.
InjectedFilePathBytes QuotaDetail `json:"injected_file_path_bytes"`
// InjectedFiles is the number of injected files allowed for each project.
InjectedFiles QuotaDetail `json:"injected_files"`
// KeyPairs is number of ssh keypairs.
KeyPairs QuotaDetail `json:"key_pairs"`
// MetadataItems is number of metadata items allowed for each instance.
MetadataItems QuotaDetail `json:"metadata_items"`
// RAM is megabytes allowed for each instance.
RAM QuotaDetail `json:"ram"`
// SecurityGroupRules is number of security group rules allowed for each
// security group.
SecurityGroupRules QuotaDetail `json:"security_group_rules"`
// SecurityGroups is the number of security groups allowed for each project.
SecurityGroups QuotaDetail `json:"security_groups"`
// Cores is number of instance cores allowed for each project.
Cores QuotaDetail `json:"cores"`
// Instances is number of instances allowed for each project.
Instances QuotaDetail `json:"instances"`
// ServerGroups is the number of ServerGroups allowed for the project.
ServerGroups QuotaDetail `json:"server_groups"`
// ServerGroupMembers is the number of members for each ServerGroup.
ServerGroupMembers QuotaDetail `json:"server_group_members"`
}
// QuotaDetail is a set of details about a single operational limit that allows
// for control of compute usage.
type QuotaDetail struct {
// InUse is the current number of provisioned/allocated resources of the
// given type.
InUse int `json:"in_use"`
// Reserved is a transitional state when a claim against quota has been made
// but the resource is not yet fully online.
Reserved int `json:"reserved"`
// Limit is the maximum number of a given resource that can be
// allocated/provisioned. This is what "quota" usually refers to.
Limit int `json:"limit"`
}
// QuotaSetPage stores a single page of all QuotaSet results from a List call.
type QuotaSetPage struct {
pagination.SinglePageBase
}
// IsEmpty determines whether or not a QuotaSetsetPage is empty.
func (page QuotaSetPage) IsEmpty() (bool, error) {
ks, err := ExtractQuotaSets(page)
return len(ks) == 0, err
}
// ExtractQuotaSets interprets a page of results as a slice of QuotaSets.
func ExtractQuotaSets(r pagination.Page) ([]QuotaSet, error) {
var s struct {
QuotaSets []QuotaSet `json:"quotas"`
}
err := (r.(QuotaSetPage)).ExtractInto(&s)
return s.QuotaSets, err
}
type quotaResult struct {
gophercloud.Result
}
// Extract is a method that attempts to interpret any QuotaSet resource response
// as a QuotaSet struct.
func (r quotaResult) Extract() (*QuotaSet, error) {
var s struct {
QuotaSet *QuotaSet `json:"quota_set"`
}
err := r.ExtractInto(&s)
return s.QuotaSet, err
}
// GetResult is the response from a Get operation. Call its Extract method to
// interpret it as a QuotaSet.
type GetResult struct {
quotaResult
}
// UpdateResult is the response from a Update operation. Call its Extract method
// to interpret it as a QuotaSet.
type UpdateResult struct {
quotaResult
}
// DeleteResult is the response from a Delete operation. Call its Extract method
// to interpret it as a QuotaSet.
type DeleteResult struct {
quotaResult
}
type quotaDetailResult struct {
gophercloud.Result
}
// GetDetailResult is the response from a Get operation. Call its Extract
// method to interpret it as a QuotaSet.
type GetDetailResult struct {
quotaDetailResult
}
// Extract is a method that attempts to interpret any QuotaDetailSet
// resource response as a set of QuotaDetailSet structs.
func (r quotaDetailResult) Extract() (QuotaDetailSet, error) {
var s struct {
QuotaData QuotaDetailSet `json:"quota_set"`
}
err := r.ExtractInto(&s)
return s.QuotaData, err
}
type GetDefaultResult struct {
quotaResult
}
func (r GetDefaultResult) Extract() (QuotaSet, error) {
var s struct {
QuotaData QuotaSet `json:"quota_set"`
}
err := r.ExtractInto(&s)
return s.QuotaData, err
}
type GetLimitResult struct {
quotaResult
}
func (r GetLimitResult) Extract() (Limits, error) {
var s struct {
QuotaData Limits `json:"limits"`
}
err := r.ExtractInto(&s)
return s.QuotaData, err
}
type Limits struct {
Rate []int `json:"rate"`
Absolute Absolute `json:"absolute"`
}
type Absolute struct {
MaxServerMeta int `json:"maxServerMeta"`
MaxPersonality int `json:"maxPersonality"`
TotalServerGroupsUsed int `json:"totalServerGroupsUsed"`
MaxImageMeta int `json:"maxImageMeta"`
MaxPersonalitySize int `json:"maxPersonalitySize"`
MaxTotalRAMSize int `json:"maxTotalRAMSize"`
MaxTotalKeypairs int `json:"maxTotalKeypairs"`
MaxSecurityGroupRules int `json:"maxSecurityGroupRules"`
MaxServerGroups int `json:"maxServerGroups"`
TotalCoresUsed int `json:"totalCoresUsed"`
TotalRAMUsed int `json:"totalRAMUsed"`
MaxSecurityGroups int `json:"maxSecurityGroups"`
TotalFloatingIpsUsed int `json:"totalFloatingIpsUsed"`
TotalInstancesUsed int `json:"totalInstancesUsed"`
TotalSecurityGroupsUsed int `json:"totalSecurityGroupsUsed"`
MaxTotalFloatingIps int `json:"maxTotalFloatingIps"`
MaxTotalInstances int `json:"maxTotalInstances"`
MaxTotalCores int `json:"maxTotalCores"`
MaxServerGroupMembers int `json:"maxServerGroupMembers"`
}