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