|
| 1 | +package quotasets |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/mitchellh/mapstructure" |
| 5 | + "github.com/rackspace/gophercloud" |
| 6 | + "github.com/rackspace/gophercloud/pagination" |
| 7 | +) |
| 8 | + |
| 9 | +// QuotaSet is a set of operational limits that allow for control of compute usage. |
| 10 | +type QuotaSet struct { |
| 11 | + //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"` |
| 15 | + // FloatingIps is number of floating ips alloted this quota_set |
| 16 | + 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 | + |
| 39 | +// QuotaSetPage stores a single, only page of QuotaSet results from a List call. |
| 40 | +type QuotaSetPage struct { |
| 41 | + pagination.SinglePageBase |
| 42 | +} |
| 43 | + |
| 44 | +// IsEmpty determines whether or not a QuotaSetsetPage is empty. |
| 45 | +func (page QuotaSetPage) IsEmpty() (bool, error) { |
| 46 | + ks, err := ExtractQuotaSets(page) |
| 47 | + return len(ks) == 0, err |
| 48 | +} |
| 49 | + |
| 50 | +// ExtractQuotaSets interprets a page of results as a slice of QuotaSets. |
| 51 | +func ExtractQuotaSets(page pagination.Page) ([]QuotaSet, error) { |
| 52 | + var resp struct { |
| 53 | + QuotaSets []QuotaSet `mapstructure:"quotas"` |
| 54 | + } |
| 55 | + |
| 56 | + err := mapstructure.Decode(page.(QuotaSetPage).Body, &resp) |
| 57 | + results := make([]QuotaSet, len(resp.QuotaSets)) |
| 58 | + for i, q := range resp.QuotaSets { |
| 59 | + results[i] = q |
| 60 | + } |
| 61 | + return results, err |
| 62 | +} |
| 63 | + |
| 64 | +type quotaResult struct { |
| 65 | + gophercloud.Result |
| 66 | +} |
| 67 | + |
| 68 | +// Extract is a method that attempts to interpret any QuotaSet resource response as a QuotaSet struct. |
| 69 | +func (r quotaResult) Extract() (*QuotaSet, error) { |
| 70 | + if r.Err != nil { |
| 71 | + return nil, r.Err |
| 72 | + } |
| 73 | + |
| 74 | + var res struct { |
| 75 | + QuotaSet *QuotaSet `json:"quota_set" mapstructure:"quota_set"` |
| 76 | + } |
| 77 | + |
| 78 | + err := mapstructure.Decode(r.Body, &res) |
| 79 | + return res.QuotaSet, err |
| 80 | +} |
| 81 | + |
| 82 | +// GetResult is the response from a Get operation. Call its Extract method to interpret it |
| 83 | +// as a QuotaSet. |
| 84 | +type GetResult struct { |
| 85 | + quotaResult |
| 86 | +} |
0 commit comments