| Ildar Svetlov | 9ae28ba | 2020-03-27 15:01:41 +0400 | [diff] [blame^] | 1 | package quotasets |
| 2 | |
| 3 | import ( |
| 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. |
| 10 | type 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. |
| 41 | type 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. |
| 86 | type 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. |
| 104 | type QuotaSetPage struct { |
| 105 | pagination.SinglePageBase |
| 106 | } |
| 107 | |
| 108 | // IsEmpty determines whether or not a QuotaSetsetPage is empty. |
| 109 | func (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. |
| 115 | func 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 | |
| 123 | type 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. |
| 129 | func (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. |
| 139 | type 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. |
| 145 | type UpdateResult struct { |
| 146 | quotaResult |
| 147 | } |
| 148 | |
| 149 | type 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. |
| 155 | type 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. |
| 161 | func (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. |
| 171 | type DeleteResult struct { |
| 172 | gophercloud.ErrResult |
| 173 | } |