blob: 44e6b0602818dae3f0ce27cf07edacabf2045018 [file] [log] [blame]
Dan Kirkwoodc0a80992016-03-07 13:47:25 -07001package quotasets
Dan Kirkwoodceb84092016-03-01 13:58:34 -07002
3import (
jrperritt3d966162016-06-06 14:08:54 -05004 "github.com/gophercloud/gophercloud"
5 "github.com/gophercloud/gophercloud/pagination"
Dan Kirkwoodceb84092016-03-01 13:58:34 -07006)
7
Dan Kirkwood7e8d8ed2016-03-08 14:05:57 -07008// QuotaSet is a set of operational limits that allow for control of compute usage.
Dan Kirkwood7e8d8ed2016-03-08 14:05:57 -07009type QuotaSet struct {
Dan Kirkwoodceb84092016-03-01 13:58:34 -070010 //ID is tenant associated with this quota_set
jrperritt3d966162016-06-06 14:08:54 -050011 ID string `json:"id"`
Dan Kirkwoodceb84092016-03-01 13:58:34 -070012 //FixedIps is number of fixed ips alloted this quota_set
jrperritt3d966162016-06-06 14:08:54 -050013 FixedIps int `json:"fixed_ips"`
Dan Kirkwood7aadf862016-03-16 12:41:11 -060014 // FloatingIps is number of floating ips alloted this quota_set
jrperritt3d966162016-06-06 14:08:54 -050015 FloatingIps int `json:"floating_ips"`
Dan Kirkwoodceb84092016-03-01 13:58:34 -070016 // InjectedFileContentBytes is content bytes allowed for each injected file
jrperritt3d966162016-06-06 14:08:54 -050017 InjectedFileContentBytes int `json:"injected_file_content_bytes"`
Dan Kirkwoodceb84092016-03-01 13:58:34 -070018 // InjectedFilePathBytes is allowed bytes for each injected file path
jrperritt3d966162016-06-06 14:08:54 -050019 InjectedFilePathBytes int `json:"injected_file_path_bytes"`
Dan Kirkwoodceb84092016-03-01 13:58:34 -070020 // InjectedFiles is injected files allowed for each project
jrperritt3d966162016-06-06 14:08:54 -050021 InjectedFiles int `json:"injected_files"`
Dan Kirkwoodceb84092016-03-01 13:58:34 -070022 // KeyPairs is number of ssh keypairs
dbaumgartenc2bb4912017-01-19 17:14:08 +010023 KeyPairs int `json:"key_pairs"`
Dan Kirkwoodceb84092016-03-01 13:58:34 -070024 // MetadataItems is number of metadata items allowed for each instance
jrperritt3d966162016-06-06 14:08:54 -050025 MetadataItems int `json:"metadata_items"`
Dan Kirkwoodceb84092016-03-01 13:58:34 -070026 // Ram is megabytes allowed for each instance
jrperritt3d966162016-06-06 14:08:54 -050027 Ram int `json:"ram"`
Dan Kirkwoodceb84092016-03-01 13:58:34 -070028 // SecurityGroupRules is rules allowed for each security group
jrperritt3d966162016-06-06 14:08:54 -050029 SecurityGroupRules int `json:"security_group_rules"`
Dan Kirkwoodceb84092016-03-01 13:58:34 -070030 // SecurityGroups security groups allowed for each project
jrperritt3d966162016-06-06 14:08:54 -050031 SecurityGroups int `json:"security_groups"`
Dan Kirkwoodceb84092016-03-01 13:58:34 -070032 // Cores is number of instance cores allowed for each project
jrperritt3d966162016-06-06 14:08:54 -050033 Cores int `json:"cores"`
Dan Kirkwoodceb84092016-03-01 13:58:34 -070034 // Instances is number of instances allowed for each project
jrperritt3d966162016-06-06 14:08:54 -050035 Instances int `json:"instances"`
dbaumgartenc2bb4912017-01-19 17:14:08 +010036 // 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 Kirkwoodceb84092016-03-01 13:58:34 -070040}
41
Dan Kirkwood7e8d8ed2016-03-08 14:05:57 -070042// QuotaSetPage stores a single, only page of QuotaSet results from a List call.
43type QuotaSetPage struct {
Dan Kirkwoodceb84092016-03-01 13:58:34 -070044 pagination.SinglePageBase
45}
46
Dan Kirkwood7e8d8ed2016-03-08 14:05:57 -070047// IsEmpty determines whether or not a QuotaSetsetPage is empty.
48func (page QuotaSetPage) IsEmpty() (bool, error) {
49 ks, err := ExtractQuotaSets(page)
Dan Kirkwoodceb84092016-03-01 13:58:34 -070050 return len(ks) == 0, err
51}
52
Dan Kirkwood7e8d8ed2016-03-08 14:05:57 -070053// ExtractQuotaSets interprets a page of results as a slice of QuotaSets.
jrperritt3d966162016-06-06 14:08:54 -050054func ExtractQuotaSets(r pagination.Page) ([]QuotaSet, error) {
55 var s struct {
56 QuotaSets []QuotaSet `json:"quotas"`
Dan Kirkwoodceb84092016-03-01 13:58:34 -070057 }
jrperritt3d966162016-06-06 14:08:54 -050058 err := (r.(QuotaSetPage)).ExtractInto(&s)
59 return s.QuotaSets, err
Dan Kirkwoodceb84092016-03-01 13:58:34 -070060}
61
62type quotaResult struct {
63 gophercloud.Result
64}
65
Dan Kirkwood7e8d8ed2016-03-08 14:05:57 -070066// Extract is a method that attempts to interpret any QuotaSet resource response as a QuotaSet struct.
67func (r quotaResult) Extract() (*QuotaSet, error) {
jrperritt3d966162016-06-06 14:08:54 -050068 var s struct {
69 QuotaSet *QuotaSet `json:"quota_set"`
Dan Kirkwoodceb84092016-03-01 13:58:34 -070070 }
jrperritt3d966162016-06-06 14:08:54 -050071 err := r.ExtractInto(&s)
72 return s.QuotaSet, err
Dan Kirkwoodceb84092016-03-01 13:58:34 -070073}
74
Dan Kirkwoodceb84092016-03-01 13:58:34 -070075// GetResult is the response from a Get operation. Call its Extract method to interpret it
Dan Kirkwood7e8d8ed2016-03-08 14:05:57 -070076// as a QuotaSet.
Dan Kirkwoodceb84092016-03-01 13:58:34 -070077type GetResult struct {
78 quotaResult
79}
dbaumgartenc2bb4912017-01-19 17:14:08 +010080
81// UpdateResult is the response from a Update operation. Call its Extract method to interpret it
82// as a QuotaSet.
83type 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.
89type DeleteResult struct {
90 quotaResult
91}