blob: 61b827dfc9419f59a9d03f133dd5c480472da716 [file] [log] [blame]
Dan Kirkwoodc0a80992016-03-07 13:47:25 -07001package quotasets
Dan Kirkwoodceb84092016-03-01 13:58:34 -07002
3import (
Krzysztof Szukiełojć3f41d082017-05-07 14:43:06 +02004 "gerrit.mcp.mirantis.net/debian/gophercloud.git"
Dan Kirkwoodceb84092016-03-01 13:58:34 -07005)
6
Dan Kirkwood7e8d8ed2016-03-08 14:05:57 -07007// Get returns public data about a previously created QuotaSet.
Dan Kirkwoodb0688252016-03-07 13:28:50 -07008func Get(client *gophercloud.ServiceClient, tenantID string) GetResult {
Dan Kirkwoodceb84092016-03-01 13:58:34 -07009 var res GetResult
Dan Kirkwoodb0688252016-03-07 13:28:50 -070010 _, res.Err = client.Get(getURL(client, tenantID), &res.Body, nil)
Dan Kirkwoodceb84092016-03-01 13:58:34 -070011 return res
12}
dbaumgartenc2bb4912017-01-19 17:14:08 +010013
14//Updates the quotas for the given tenantID and returns the new quota-set
15func 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
27func 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
35type 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
68type 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
73func (opts UpdateOpts) ToComputeQuotaUpdateMap() (map[string]interface{}, error) {
74
75 return gophercloud.BuildRequestBody(opts, "quota_set")
76}