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" |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 5 | ) |
| 6 | |
Dan Kirkwood | 7e8d8ed | 2016-03-08 14:05:57 -0700 | [diff] [blame] | 7 | // Get returns public data about a previously created QuotaSet. |
Dan Kirkwood | b068825 | 2016-03-07 13:28:50 -0700 | [diff] [blame] | 8 | func Get(client *gophercloud.ServiceClient, tenantID string) GetResult { |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 9 | var res GetResult |
Dan Kirkwood | b068825 | 2016-03-07 13:28:50 -0700 | [diff] [blame] | 10 | _, res.Err = client.Get(getURL(client, tenantID), &res.Body, nil) |
Dan Kirkwood | ceb8409 | 2016-03-01 13:58:34 -0700 | [diff] [blame] | 11 | return res |
| 12 | } |
dbaumgarten | c2bb491 | 2017-01-19 17:14:08 +0100 | [diff] [blame^] | 13 | |
| 14 | //Updates the quotas for the given tenantID and returns the new quota-set |
| 15 | func Update(client *gophercloud.ServiceClient, tenantID string, opts UpdateOptsBuilder) (res UpdateResult) { |
| 16 | reqBody, err := opts.ToComputeQuotaUpdateMap() |
| 17 | if err != nil { |
| 18 | res.Err = err |
| 19 | return |
| 20 | } |
| 21 | |
| 22 | _, res.Err = client.Put(updateURL(client, tenantID), reqBody, &res.Body, &gophercloud.RequestOpts{OkCodes: []int{200}}) |
| 23 | return res |
| 24 | } |
| 25 | |
| 26 | //Resets the uotas for the given tenant to their default values |
| 27 | func Delete(client *gophercloud.ServiceClient, tenantID string) (res DeleteResult) { |
| 28 | _, res.Err = client.Delete(deleteURL(client, tenantID), nil) |
| 29 | return |
| 30 | } |
| 31 | |
| 32 | //Options for Updating the quotas of a Tenant |
| 33 | //All int-values are pointers so they can be nil if they are not needed |
| 34 | //you can use gopercloud.IntToPointer() for convenience |
| 35 | type UpdateOpts struct { |
| 36 | //FixedIps is number of fixed ips alloted this quota_set |
| 37 | FixedIps *int `json:"fixed_ips,omitempty"` |
| 38 | // FloatingIps is number of floating ips alloted this quota_set |
| 39 | FloatingIps *int `json:"floating_ips,omitempty"` |
| 40 | // InjectedFileContentBytes is content bytes allowed for each injected file |
| 41 | InjectedFileContentBytes *int `json:"injected_file_content_bytes,omitempty"` |
| 42 | // InjectedFilePathBytes is allowed bytes for each injected file path |
| 43 | InjectedFilePathBytes *int `json:"injected_file_path_bytes,omitempty"` |
| 44 | // InjectedFiles is injected files allowed for each project |
| 45 | InjectedFiles *int `json:"injected_files,omitempty"` |
| 46 | // KeyPairs is number of ssh keypairs |
| 47 | KeyPairs *int `json:"key_pairs,omitempty"` |
| 48 | // MetadataItems is number of metadata items allowed for each instance |
| 49 | MetadataItems *int `json:"metadata_items,omitempty"` |
| 50 | // Ram is megabytes allowed for each instance |
| 51 | Ram *int `json:"ram,omitempty"` |
| 52 | // SecurityGroupRules is rules allowed for each security group |
| 53 | SecurityGroupRules *int `json:"security_group_rules,omitempty"` |
| 54 | // SecurityGroups security groups allowed for each project |
| 55 | SecurityGroups *int `json:"security_groups,omitempty"` |
| 56 | // Cores is number of instance cores allowed for each project |
| 57 | Cores *int `json:"cores,omitempty"` |
| 58 | // Instances is number of instances allowed for each project |
| 59 | Instances *int `json:"instances,omitempty"` |
| 60 | // Number of ServerGroups allowed for the project |
| 61 | ServerGroups *int `json:"server_groups,omitempty"` |
| 62 | // Max number of Members for each ServerGroup |
| 63 | ServerGroupMembers *int `json:"server_group_members,omitempty"` |
| 64 | //Users can force the update even if the quota has already been used and the reserved quota exceeds the new quota. |
| 65 | Force bool `json:"force,omitempty"` |
| 66 | } |
| 67 | |
| 68 | type UpdateOptsBuilder interface { |
| 69 | //Extra specific name to prevent collisions with interfaces for other quotas (e.g. neutron) |
| 70 | ToComputeQuotaUpdateMap() (map[string]interface{}, error) |
| 71 | } |
| 72 | |
| 73 | func (opts UpdateOpts) ToComputeQuotaUpdateMap() (map[string]interface{}, error) { |
| 74 | |
| 75 | return gophercloud.BuildRequestBody(opts, "quota_set") |
| 76 | } |
| 77 | |
| 78 | |
| 79 | |