github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/networking/v2/extensions/quotas/requests.go (about) 1 package quotas 2 3 import ( 4 "context" 5 6 "github.com/vnpaycloud-console/gophercloud/v2" 7 ) 8 9 // Get returns Networking Quotas for a project. 10 func Get(ctx context.Context, client *gophercloud.ServiceClient, projectID string) (r GetResult) { 11 resp, err := client.Get(ctx, getURL(client, projectID), &r.Body, nil) 12 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 13 return 14 } 15 16 // GetDetail returns detailed Networking Quotas for a project. 17 func GetDetail(ctx context.Context, client *gophercloud.ServiceClient, projectID string) (r GetDetailResult) { 18 resp, err := client.Get(ctx, getDetailURL(client, projectID), &r.Body, nil) 19 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 20 return 21 } 22 23 // UpdateOptsBuilder allows extensions to add additional parameters to the 24 // Update request. 25 type UpdateOptsBuilder interface { 26 ToQuotaUpdateMap() (map[string]any, error) 27 } 28 29 // UpdateOpts represents options used to update the Networking Quotas. 30 type UpdateOpts struct { 31 // FloatingIP represents a number of floating IPs. A "-1" value means no limit. 32 FloatingIP *int `json:"floatingip,omitempty"` 33 34 // Network represents a number of networks. A "-1" value means no limit. 35 Network *int `json:"network,omitempty"` 36 37 // Port represents a number of ports. A "-1" value means no limit. 38 Port *int `json:"port,omitempty"` 39 40 // RBACPolicy represents a number of RBAC policies. A "-1" value means no limit. 41 RBACPolicy *int `json:"rbac_policy,omitempty"` 42 43 // Router represents a number of routers. A "-1" value means no limit. 44 Router *int `json:"router,omitempty"` 45 46 // SecurityGroup represents a number of security groups. A "-1" value means no limit. 47 SecurityGroup *int `json:"security_group,omitempty"` 48 49 // SecurityGroupRule represents a number of security group rules. A "-1" value means no limit. 50 SecurityGroupRule *int `json:"security_group_rule,omitempty"` 51 52 // Subnet represents a number of subnets. A "-1" value means no limit. 53 Subnet *int `json:"subnet,omitempty"` 54 55 // SubnetPool represents a number of subnet pools. A "-1" value means no limit. 56 SubnetPool *int `json:"subnetpool,omitempty"` 57 58 // Trunk represents a number of trunks. A "-1" value means no limit. 59 Trunk *int `json:"trunk,omitempty"` 60 } 61 62 // ToQuotaUpdateMap builds a request body from UpdateOpts. 63 func (opts UpdateOpts) ToQuotaUpdateMap() (map[string]any, error) { 64 return gophercloud.BuildRequestBody(opts, "quota") 65 } 66 67 // Update accepts a UpdateOpts struct and updates an existing Networking Quotas using the 68 // values provided. 69 func Update(ctx context.Context, c *gophercloud.ServiceClient, projectID string, opts UpdateOptsBuilder) (r UpdateResult) { 70 b, err := opts.ToQuotaUpdateMap() 71 if err != nil { 72 r.Err = err 73 return 74 } 75 resp, err := c.Put(ctx, updateURL(c, projectID), b, &r.Body, &gophercloud.RequestOpts{ 76 OkCodes: []int{200}, 77 }) 78 _, r.Header, r.Err = gophercloud.ParseResponse(resp, err) 79 return 80 }