blob: 23e71b06918e94b6ef3d54c4f195456653b448b4 [file] [log] [blame]
Ildar Svetlov9ae28ba2020-03-27 15:01:41 +04001package quotasets
2
3import (
4 "gerrit.mcp.mirantis.net/debian/gophercloud.git"
5 "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination"
6)
7
8// QuotaSet is a set of operational limits that allow for control of block
9// storage usage.
10type QuotaSet struct {
11 // ID is project associated with this QuotaSet.
12 ID string `json:"id"`
13
14 // Volumes is the number of volumes that are allowed for each project.
15 Volumes int `json:"volumes"`
16
17 // Snapshots is the number of snapshots that are allowed for each project.
18 Snapshots int `json:"snapshots"`
19
20 // Gigabytes is the size (GB) of volumes and snapshots that are allowed for
21 // each project.
22 Gigabytes int `json:"gigabytes"`
23
24 // PerVolumeGigabytes is the size (GB) of volumes and snapshots that are
25 // allowed for each project and the specifed volume type.
26 PerVolumeGigabytes int `json:"per_volume_gigabytes"`
27
28 // Backups is the number of backups that are allowed for each project.
29 Backups int `json:"backups"`
30
31 // BackupGigabytes is the size (GB) of backups that are allowed for each
32 // project.
33 BackupGigabytes int `json:"backup_gigabytes"`
34
35 // Groups is the number of groups that are allowed for each project.
36 Groups int `json:"groups,omitempty"`
37}
38
39// QuotaUsageSet represents details of both operational limits of block
40// storage resources and the current usage of those resources.
41type QuotaUsageSet struct {
42 // ID is the project ID associated with this QuotaUsageSet.
43 ID string `json:"id"`
44
45 // Volumes is the volume usage information for this project, including
46 // in_use, limit, reserved and allocated attributes. Note: allocated
47 // attribute is available only when nested quota is enabled.
48 Volumes QuotaUsage `json:"volumes"`
49
50 // Snapshots is the snapshot usage information for this project, including
51 // in_use, limit, reserved and allocated attributes. Note: allocated
52 // attribute is available only when nested quota is enabled.
53 Snapshots QuotaUsage `json:"snapshots"`
54
55 // Gigabytes is the size (GB) usage information of volumes and snapshots
56 // for this project, including in_use, limit, reserved and allocated
57 // attributes. Note: allocated attribute is available only when nested
58 // quota is enabled.
59 Gigabytes QuotaUsage `json:"gigabytes"`
60
61 // PerVolumeGigabytes is the size (GB) usage information for each volume,
62 // including in_use, limit, reserved and allocated attributes. Note:
63 // allocated attribute is available only when nested quota is enabled and
64 // only limit is meaningful here.
65 PerVolumeGigabytes QuotaUsage `json:"per_volume_gigabytes"`
66
67 // Backups is the backup usage information for this project, including
68 // in_use, limit, reserved and allocated attributes. Note: allocated
69 // attribute is available only when nested quota is enabled.
70 Backups QuotaUsage `json:"backups"`
71
72 // BackupGigabytes is the size (GB) usage information of backup for this
73 // project, including in_use, limit, reserved and allocated attributes.
74 // Note: allocated attribute is available only when nested quota is
75 // enabled.
76 BackupGigabytes QuotaUsage `json:"backup_gigabytes"`
77
78 // Groups is the number of groups that are allowed for each project.
79 // Note: allocated attribute is available only when nested quota is
80 // enabled.
81 Groups QuotaUsage `json:"groups"`
82}
83
84// QuotaUsage is a set of details about a single operational limit that allows
85// for control of block storage usage.
86type QuotaUsage struct {
87 // InUse is the current number of provisioned resources of the given type.
88 InUse int `json:"in_use"`
89
90 // Allocated is the current number of resources of a given type allocated
91 // for use. It is only available when nested quota is enabled.
92 Allocated int `json:"allocated"`
93
94 // Reserved is a transitional state when a claim against quota has been made
95 // but the resource is not yet fully online.
96 Reserved int `json:"reserved"`
97
98 // Limit is the maximum number of a given resource that can be
99 // allocated/provisioned. This is what "quota" usually refers to.
100 Limit int `json:"limit"`
101}
102
103// QuotaSetPage stores a single page of all QuotaSet results from a List call.
104type QuotaSetPage struct {
105 pagination.SinglePageBase
106}
107
108// IsEmpty determines whether or not a QuotaSetsetPage is empty.
109func (r QuotaSetPage) IsEmpty() (bool, error) {
110 ks, err := ExtractQuotaSets(r)
111 return len(ks) == 0, err
112}
113
114// ExtractQuotaSets interprets a page of results as a slice of QuotaSets.
115func ExtractQuotaSets(r pagination.Page) ([]QuotaSet, error) {
116 var s struct {
117 QuotaSets []QuotaSet `json:"quotas"`
118 }
119 err := (r.(QuotaSetPage)).ExtractInto(&s)
120 return s.QuotaSets, err
121}
122
123type quotaResult struct {
124 gophercloud.Result
125}
126
127// Extract is a method that attempts to interpret any QuotaSet resource response
128// as a QuotaSet struct.
129func (r quotaResult) Extract() (*QuotaSet, error) {
130 var s struct {
131 QuotaSet *QuotaSet `json:"quota_set"`
132 }
133 err := r.ExtractInto(&s)
134 return s.QuotaSet, err
135}
136
137// GetResult is the response from a Get operation. Call its Extract method to
138// interpret it as a QuotaSet.
139type GetResult struct {
140 quotaResult
141}
142
143// UpdateResult is the response from a Update operation. Call its Extract method
144// to interpret it as a QuotaSet.
145type UpdateResult struct {
146 quotaResult
147}
148
149type quotaUsageResult struct {
150 gophercloud.Result
151}
152
153// GetUsageResult is the response from a Get operation. Call its Extract
154// method to interpret it as a QuotaSet.
155type GetUsageResult struct {
156 quotaUsageResult
157}
158
159// Extract is a method that attempts to interpret any QuotaUsageSet resource
160// response as a set of QuotaUsageSet structs.
161func (r quotaUsageResult) Extract() (QuotaUsageSet, error) {
162 var s struct {
163 QuotaUsageSet QuotaUsageSet `json:"quota_set"`
164 }
165 err := r.ExtractInto(&s)
166 return s.QuotaUsageSet, err
167}
168
169// DeleteResult is the response from a Delete operation. Call its ExtractErr
170// method to determine if the request succeeded or failed.
171type DeleteResult struct {
172 gophercloud.ErrResult
173}