Dan Kirkwood | c0a8099 | 2016-03-07 13:47:25 -0700 | [diff] [blame] | 1 | package quotasets |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 2 | |
| 3 | import ( |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 4 | "github.com/gophercloud/gophercloud" |
| 5 | "github.com/gophercloud/gophercloud/pagination" |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 6 | ) |
| 7 | |
Dan Kirkwood | 7e8d8ed | 2016-03-08 14:05:57 -0700 | [diff] [blame] | 8 | // QuotaSet is a set of operational limits that allow for control of compute usage. |
Dan Kirkwood | 7e8d8ed | 2016-03-08 14:05:57 -0700 | [diff] [blame] | 9 | type QuotaSet struct { |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 10 | //ID is tenant associated with this quota_set |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 11 | ID string `json:"id"` |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 12 | //FixedIps is number of fixed ips alloted this quota_set |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 13 | FixedIps int `json:"fixed_ips"` |
Dan Kirkwood | 7aadf86 | 2016-03-16 12:41:11 -0600 | [diff] [blame] | 14 | // FloatingIps is number of floating ips alloted this quota_set |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 15 | FloatingIps int `json:"floating_ips"` |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 16 | // InjectedFileContentBytes is content bytes allowed for each injected file |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 17 | InjectedFileContentBytes int `json:"injected_file_content_bytes"` |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 18 | // InjectedFilePathBytes is allowed bytes for each injected file path |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 19 | InjectedFilePathBytes int `json:"injected_file_path_bytes"` |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 20 | // InjectedFiles is injected files allowed for each project |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 21 | InjectedFiles int `json:"injected_files"` |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 22 | // KeyPairs is number of ssh keypairs |
dbaumgarten | c2bb491 | 2017-01-19 17:14:08 +0100 | [diff] [blame] | 23 | KeyPairs int `json:"key_pairs"` |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 24 | // MetadataItems is number of metadata items allowed for each instance |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 25 | MetadataItems int `json:"metadata_items"` |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 26 | // Ram is megabytes allowed for each instance |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 27 | Ram int `json:"ram"` |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 28 | // SecurityGroupRules is rules allowed for each security group |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 29 | SecurityGroupRules int `json:"security_group_rules"` |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 30 | // SecurityGroups security groups allowed for each project |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 31 | SecurityGroups int `json:"security_groups"` |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 32 | // Cores is number of instance cores allowed for each project |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 33 | Cores int `json:"cores"` |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 34 | // Instances is number of instances allowed for each project |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 35 | Instances int `json:"instances"` |
dbaumgarten | c2bb491 | 2017-01-19 17:14:08 +0100 | [diff] [blame] | 36 | // Number of ServerGroups allowed for the project |
| 37 | ServerGroups int `json:"server_groups"` |
| 38 | // Max number of Members for each ServerGroup |
| 39 | ServerGroupMembers int `json:"server_group_members"` |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Dan Kirkwood | 7e8d8ed | 2016-03-08 14:05:57 -0700 | [diff] [blame] | 42 | // QuotaSetPage stores a single, only page of QuotaSet results from a List call. |
| 43 | type QuotaSetPage struct { |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 44 | pagination.SinglePageBase |
| 45 | } |
| 46 | |
Dan Kirkwood | 7e8d8ed | 2016-03-08 14:05:57 -0700 | [diff] [blame] | 47 | // IsEmpty determines whether or not a QuotaSetsetPage is empty. |
| 48 | func (page QuotaSetPage) IsEmpty() (bool, error) { |
| 49 | ks, err := ExtractQuotaSets(page) |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 50 | return len(ks) == 0, err |
| 51 | } |
| 52 | |
Dan Kirkwood | 7e8d8ed | 2016-03-08 14:05:57 -0700 | [diff] [blame] | 53 | // ExtractQuotaSets interprets a page of results as a slice of QuotaSets. |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 54 | func ExtractQuotaSets(r pagination.Page) ([]QuotaSet, error) { |
| 55 | var s struct { |
| 56 | QuotaSets []QuotaSet `json:"quotas"` |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 57 | } |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 58 | err := (r.(QuotaSetPage)).ExtractInto(&s) |
| 59 | return s.QuotaSets, err |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | type quotaResult struct { |
| 63 | gophercloud.Result |
| 64 | } |
| 65 | |
Dan Kirkwood | 7e8d8ed | 2016-03-08 14:05:57 -0700 | [diff] [blame] | 66 | // Extract is a method that attempts to interpret any QuotaSet resource response as a QuotaSet struct. |
| 67 | func (r quotaResult) Extract() (*QuotaSet, error) { |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 68 | var s struct { |
| 69 | QuotaSet *QuotaSet `json:"quota_set"` |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 70 | } |
jrperritt | 3d96616 | 2016-06-06 14:08:54 -0500 | [diff] [blame] | 71 | err := r.ExtractInto(&s) |
| 72 | return s.QuotaSet, err |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 73 | } |
| 74 | |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 75 | // GetResult is the response from a Get operation. Call its Extract method to interpret it |
Dan Kirkwood | 7e8d8ed | 2016-03-08 14:05:57 -0700 | [diff] [blame] | 76 | // as a QuotaSet. |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 77 | type GetResult struct { |
| 78 | quotaResult |
| 79 | } |
dbaumgarten | c2bb491 | 2017-01-19 17:14:08 +0100 | [diff] [blame] | 80 | |
| 81 | // UpdateResult is the response from a Update operation. Call its Extract method to interpret it |
| 82 | // as a QuotaSet. |
| 83 | type UpdateResult struct { |
| 84 | quotaResult |
| 85 | } |
| 86 | |
| 87 | // DeleteResult is the response from a Delete operation. Call its Extract method to interpret it |
| 88 | // as a QuotaSet. |
| 89 | type DeleteResult struct { |
| 90 | quotaResult |
| 91 | } |