github.com/gophercloud/gophercloud@v1.11.0/openstack/blockstorage/extensions/quotasets/results.go (about) 1 package quotasets 2 3 import ( 4 "encoding/json" 5 6 "github.com/gophercloud/gophercloud" 7 "github.com/gophercloud/gophercloud/pagination" 8 ) 9 10 // QuotaSet is a set of operational limits that allow for control of block 11 // storage usage. 12 type QuotaSet struct { 13 // ID is project associated with this QuotaSet. 14 ID string `json:"id"` 15 16 // Volumes is the number of volumes that are allowed for each project. 17 Volumes int `json:"volumes"` 18 19 // Snapshots is the number of snapshots that are allowed for each project. 20 Snapshots int `json:"snapshots"` 21 22 // Gigabytes is the size (GB) of volumes and snapshots that are allowed for 23 // each project. 24 Gigabytes int `json:"gigabytes"` 25 26 // PerVolumeGigabytes is the size (GB) of volumes and snapshots that are 27 // allowed for each project and the specifed volume type. 28 PerVolumeGigabytes int `json:"per_volume_gigabytes"` 29 30 // Backups is the number of backups that are allowed for each project. 31 Backups int `json:"backups"` 32 33 // BackupGigabytes is the size (GB) of backups that are allowed for each 34 // project. 35 BackupGigabytes int `json:"backup_gigabytes"` 36 37 // Groups is the number of groups that are allowed for each project. 38 Groups int `json:"groups,omitempty"` 39 40 // Extra is a collection of miscellaneous key/values used to set 41 // quota per volume_type 42 Extra map[string]interface{} `json:"-"` 43 } 44 45 // UnmarshalJSON is used on QuotaSet to unmarshal extra keys that are 46 // used for volume_type quota 47 func (r *QuotaSet) UnmarshalJSON(b []byte) error { 48 type tmp QuotaSet 49 var s struct { 50 tmp 51 Extra map[string]interface{} `json:"extra"` 52 } 53 err := json.Unmarshal(b, &s) 54 if err != nil { 55 return err 56 } 57 *r = QuotaSet(s.tmp) 58 59 var result interface{} 60 err = json.Unmarshal(b, &result) 61 if err != nil { 62 return err 63 } 64 if resultMap, ok := result.(map[string]interface{}); ok { 65 r.Extra = gophercloud.RemainingKeys(QuotaSet{}, resultMap) 66 } 67 68 return err 69 } 70 71 // QuotaUsageSet represents details of both operational limits of block 72 // storage resources and the current usage of those resources. 73 type QuotaUsageSet struct { 74 // ID is the project ID associated with this QuotaUsageSet. 75 ID string `json:"id"` 76 77 // Volumes is the volume usage information for this project, including 78 // in_use, limit, reserved and allocated attributes. Note: allocated 79 // attribute is available only when nested quota is enabled. 80 Volumes QuotaUsage `json:"volumes"` 81 82 // Snapshots is the snapshot usage information for this project, including 83 // in_use, limit, reserved and allocated attributes. Note: allocated 84 // attribute is available only when nested quota is enabled. 85 Snapshots QuotaUsage `json:"snapshots"` 86 87 // Gigabytes is the size (GB) usage information of volumes and snapshots 88 // for this project, including in_use, limit, reserved and allocated 89 // attributes. Note: allocated attribute is available only when nested 90 // quota is enabled. 91 Gigabytes QuotaUsage `json:"gigabytes"` 92 93 // PerVolumeGigabytes is the size (GB) usage information for each volume, 94 // including in_use, limit, reserved and allocated attributes. Note: 95 // allocated attribute is available only when nested quota is enabled and 96 // only limit is meaningful here. 97 PerVolumeGigabytes QuotaUsage `json:"per_volume_gigabytes"` 98 99 // Backups is the backup usage information for this project, including 100 // in_use, limit, reserved and allocated attributes. Note: allocated 101 // attribute is available only when nested quota is enabled. 102 Backups QuotaUsage `json:"backups"` 103 104 // BackupGigabytes is the size (GB) usage information of backup for this 105 // project, including in_use, limit, reserved and allocated attributes. 106 // Note: allocated attribute is available only when nested quota is 107 // enabled. 108 BackupGigabytes QuotaUsage `json:"backup_gigabytes"` 109 110 // Groups is the number of groups that are allowed for each project. 111 // Note: allocated attribute is available only when nested quota is 112 // enabled. 113 Groups QuotaUsage `json:"groups"` 114 } 115 116 // QuotaUsage is a set of details about a single operational limit that allows 117 // for control of block storage usage. 118 type QuotaUsage struct { 119 // InUse is the current number of provisioned resources of the given type. 120 InUse int `json:"in_use"` 121 122 // Allocated is the current number of resources of a given type allocated 123 // for use. It is only available when nested quota is enabled. 124 Allocated int `json:"allocated"` 125 126 // Reserved is a transitional state when a claim against quota has been made 127 // but the resource is not yet fully online. 128 Reserved int `json:"reserved"` 129 130 // Limit is the maximum number of a given resource that can be 131 // allocated/provisioned. This is what "quota" usually refers to. 132 Limit int `json:"limit"` 133 } 134 135 // QuotaSetPage stores a single page of all QuotaSet results from a List call. 136 type QuotaSetPage struct { 137 pagination.SinglePageBase 138 } 139 140 // IsEmpty determines whether or not a QuotaSetsetPage is empty. 141 func (r QuotaSetPage) IsEmpty() (bool, error) { 142 if r.StatusCode == 204 { 143 return true, nil 144 } 145 146 ks, err := ExtractQuotaSets(r) 147 return len(ks) == 0, err 148 } 149 150 // ExtractQuotaSets interprets a page of results as a slice of QuotaSets. 151 func ExtractQuotaSets(r pagination.Page) ([]QuotaSet, error) { 152 var s struct { 153 QuotaSets []QuotaSet `json:"quotas"` 154 } 155 err := (r.(QuotaSetPage)).ExtractInto(&s) 156 return s.QuotaSets, err 157 } 158 159 type quotaResult struct { 160 gophercloud.Result 161 } 162 163 // Extract is a method that attempts to interpret any QuotaSet resource response 164 // as a QuotaSet struct. 165 func (r quotaResult) Extract() (*QuotaSet, error) { 166 var s struct { 167 QuotaSet *QuotaSet `json:"quota_set"` 168 } 169 err := r.ExtractInto(&s) 170 return s.QuotaSet, err 171 } 172 173 // GetResult is the response from a Get operation. Call its Extract method to 174 // interpret it as a QuotaSet. 175 type GetResult struct { 176 quotaResult 177 } 178 179 // UpdateResult is the response from a Update operation. Call its Extract method 180 // to interpret it as a QuotaSet. 181 type UpdateResult struct { 182 quotaResult 183 } 184 185 type quotaUsageResult struct { 186 gophercloud.Result 187 } 188 189 // GetUsageResult is the response from a Get operation. Call its Extract 190 // method to interpret it as a QuotaSet. 191 type GetUsageResult struct { 192 quotaUsageResult 193 } 194 195 // Extract is a method that attempts to interpret any QuotaUsageSet resource 196 // response as a set of QuotaUsageSet structs. 197 func (r quotaUsageResult) Extract() (QuotaUsageSet, error) { 198 var s struct { 199 QuotaUsageSet QuotaUsageSet `json:"quota_set"` 200 } 201 err := r.ExtractInto(&s) 202 return s.QuotaUsageSet, err 203 } 204 205 // DeleteResult is the response from a Delete operation. Call its ExtractErr 206 // method to determine if the request succeeded or failed. 207 type DeleteResult struct { 208 gophercloud.ErrResult 209 }