blob: cbf4d6b82c92e62fc07226d36c0172eaacc02078 [file] [log] [blame]
Dan Kirkwoodc0a80992016-03-07 13:47:25 -07001package quotasets
Dan Kirkwoodceb84092016-03-01 13:58:34 -07002
3import (
4 "github.com/mitchellh/mapstructure"
5 "github.com/rackspace/gophercloud"
6 "github.com/rackspace/gophercloud/pagination"
7)
8
Dan Kirkwood7e8d8ed2016-03-08 14:05:57 -07009// QuotaSet is a set of operational limits that allow for control of compute usage.
Dan Kirkwood7e8d8ed2016-03-08 14:05:57 -070010type QuotaSet struct {
Dan Kirkwoodceb84092016-03-01 13:58:34 -070011 //ID is tenant associated with this quota_set
12 ID string `mapstructure:"id"`
13 //FixedIps is number of fixed ips alloted this quota_set
14 FixedIps int `mapstructure:"fixed_ips"`
Dan Kirkwood7aadf862016-03-16 12:41:11 -060015 // FloatingIps is number of floating ips alloted this quota_set
Dan Kirkwoodceb84092016-03-01 13:58:34 -070016 FloatingIps int `mapstructure:"floating_ips"`
17 // InjectedFileContentBytes is content bytes allowed for each injected file
18 InjectedFileContentBytes int `mapstructure:"injected_file_content_bytes"`
19 // InjectedFilePathBytes is allowed bytes for each injected file path
20 InjectedFilePathBytes int `mapstructure:"injected_file_path_bytes"`
21 // InjectedFiles is injected files allowed for each project
22 InjectedFiles int `mapstructure:"injected_files"`
23 // KeyPairs is number of ssh keypairs
24 KeyPairs int `mapstructure:"keypairs"`
25 // MetadataItems is number of metadata items allowed for each instance
26 MetadataItems int `mapstructure:"metadata_items"`
27 // Ram is megabytes allowed for each instance
28 Ram int `mapstructure:"ram"`
29 // SecurityGroupRules is rules allowed for each security group
30 SecurityGroupRules int `mapstructure:"security_group_rules"`
31 // SecurityGroups security groups allowed for each project
32 SecurityGroups int `mapstructure:"security_groups"`
33 // Cores is number of instance cores allowed for each project
34 Cores int `mapstructure:"cores"`
35 // Instances is number of instances allowed for each project
36 Instances int `mapstructure:"instances"`
37}
38
Dan Kirkwood7e8d8ed2016-03-08 14:05:57 -070039// QuotaSetPage stores a single, only page of QuotaSet results from a List call.
40type QuotaSetPage struct {
Dan Kirkwoodceb84092016-03-01 13:58:34 -070041 pagination.SinglePageBase
42}
43
Dan Kirkwood7e8d8ed2016-03-08 14:05:57 -070044// IsEmpty determines whether or not a QuotaSetsetPage is empty.
45func (page QuotaSetPage) IsEmpty() (bool, error) {
46 ks, err := ExtractQuotaSets(page)
Dan Kirkwoodceb84092016-03-01 13:58:34 -070047 return len(ks) == 0, err
48}
49
Dan Kirkwood7e8d8ed2016-03-08 14:05:57 -070050// ExtractQuotaSets interprets a page of results as a slice of QuotaSets.
51func ExtractQuotaSets(page pagination.Page) ([]QuotaSet, error) {
Dan Kirkwoodceb84092016-03-01 13:58:34 -070052 var resp struct {
Dan Kirkwood7e8d8ed2016-03-08 14:05:57 -070053 QuotaSets []QuotaSet `mapstructure:"quotas"`
Dan Kirkwoodceb84092016-03-01 13:58:34 -070054 }
55
Dan Kirkwood7e8d8ed2016-03-08 14:05:57 -070056 err := mapstructure.Decode(page.(QuotaSetPage).Body, &resp)
57 results := make([]QuotaSet, len(resp.QuotaSets))
58 for i, q := range resp.QuotaSets {
Dan Kirkwoodceb84092016-03-01 13:58:34 -070059 results[i] = q
60 }
61 return results, err
62}
63
64type quotaResult struct {
65 gophercloud.Result
66}
67
Dan Kirkwood7e8d8ed2016-03-08 14:05:57 -070068// Extract is a method that attempts to interpret any QuotaSet resource response as a QuotaSet struct.
69func (r quotaResult) Extract() (*QuotaSet, error) {
Dan Kirkwoodceb84092016-03-01 13:58:34 -070070 if r.Err != nil {
71 return nil, r.Err
72 }
73
74 var res struct {
Dan Kirkwood7e8d8ed2016-03-08 14:05:57 -070075 QuotaSet *QuotaSet `json:"quota_set" mapstructure:"quota_set"`
Dan Kirkwoodceb84092016-03-01 13:58:34 -070076 }
77
78 err := mapstructure.Decode(r.Body, &res)
Dan Kirkwood7e8d8ed2016-03-08 14:05:57 -070079 return res.QuotaSet, err
Dan Kirkwoodceb84092016-03-01 13:58:34 -070080}
81
Dan Kirkwoodceb84092016-03-01 13:58:34 -070082// GetResult is the response from a Get operation. Call its Extract method to interpret it
Dan Kirkwood7e8d8ed2016-03-08 14:05:57 -070083// as a QuotaSet.
Dan Kirkwoodceb84092016-03-01 13:58:34 -070084type GetResult struct {
85 quotaResult
86}