github.com/gophercloud/gophercloud@v1.11.0/openstack/compute/v2/extensions/quotasets/requests.go (about) 1 package quotasets 2 3 import ( 4 "github.com/gophercloud/gophercloud" 5 ) 6 7 // Get returns public data about a previously created QuotaSet. 8 func Get(client *gophercloud.ServiceClient, tenantID string) (r GetResult) { 9 resp, err := client.Get(getURL(client, tenantID), &r.Body, nil) 10 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 11 return 12 } 13 14 // GetDetail returns detailed public data about a previously created QuotaSet. 15 func GetDetail(client *gophercloud.ServiceClient, tenantID string) (r GetDetailResult) { 16 resp, err := client.Get(getDetailURL(client, tenantID), &r.Body, nil) 17 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 18 return 19 } 20 21 // Updates the quotas for the given tenantID and returns the new QuotaSet. 22 func Update(client *gophercloud.ServiceClient, tenantID string, opts UpdateOptsBuilder) (r UpdateResult) { 23 reqBody, err := opts.ToComputeQuotaUpdateMap() 24 if err != nil { 25 r.Err = err 26 return 27 } 28 29 resp, err := client.Put(updateURL(client, tenantID), reqBody, &r.Body, &gophercloud.RequestOpts{OkCodes: []int{200}}) 30 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 31 return 32 } 33 34 // Resets the quotas for the given tenant to their default values. 35 func Delete(client *gophercloud.ServiceClient, tenantID string) (r DeleteResult) { 36 resp, err := client.Delete(deleteURL(client, tenantID), nil) 37 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 38 return 39 } 40 41 // Options for Updating the quotas of a Tenant. 42 // All int-values are pointers so they can be nil if they are not needed. 43 // You can use gopercloud.IntToPointer() for convenience 44 type UpdateOpts struct { 45 // FixedIPs is number of fixed ips allotted this quota_set. 46 FixedIPs *int `json:"fixed_ips,omitempty"` 47 48 // FloatingIPs is number of floating ips allotted this quota_set. 49 FloatingIPs *int `json:"floating_ips,omitempty"` 50 51 // InjectedFileContentBytes is content bytes allowed for each injected file. 52 InjectedFileContentBytes *int `json:"injected_file_content_bytes,omitempty"` 53 54 // InjectedFilePathBytes is allowed bytes for each injected file path. 55 InjectedFilePathBytes *int `json:"injected_file_path_bytes,omitempty"` 56 57 // InjectedFiles is injected files allowed for each project. 58 InjectedFiles *int `json:"injected_files,omitempty"` 59 60 // KeyPairs is number of ssh keypairs. 61 KeyPairs *int `json:"key_pairs,omitempty"` 62 63 // MetadataItems is number of metadata items allowed for each instance. 64 MetadataItems *int `json:"metadata_items,omitempty"` 65 66 // RAM is megabytes allowed for each instance. 67 RAM *int `json:"ram,omitempty"` 68 69 // SecurityGroupRules is rules allowed for each security group. 70 SecurityGroupRules *int `json:"security_group_rules,omitempty"` 71 72 // SecurityGroups security groups allowed for each project. 73 SecurityGroups *int `json:"security_groups,omitempty"` 74 75 // Cores is number of instance cores allowed for each project. 76 Cores *int `json:"cores,omitempty"` 77 78 // Instances is number of instances allowed for each project. 79 Instances *int `json:"instances,omitempty"` 80 81 // Number of ServerGroups allowed for the project. 82 ServerGroups *int `json:"server_groups,omitempty"` 83 84 // Max number of Members for each ServerGroup. 85 ServerGroupMembers *int `json:"server_group_members,omitempty"` 86 87 // Force will update the quotaset even if the quota has already been used 88 // and the reserved quota exceeds the new quota. 89 Force bool `json:"force,omitempty"` 90 } 91 92 // UpdateOptsBuilder enables extensins to add parameters to the update request. 93 type UpdateOptsBuilder interface { 94 // Extra specific name to prevent collisions with interfaces for other quotas 95 // (e.g. neutron) 96 ToComputeQuotaUpdateMap() (map[string]interface{}, error) 97 } 98 99 // ToComputeQuotaUpdateMap builds the update options into a serializable 100 // format. 101 func (opts UpdateOpts) ToComputeQuotaUpdateMap() (map[string]interface{}, error) { 102 return gophercloud.BuildRequestBody(opts, "quota_set") 103 }