github.com/vnpaycloud-console/gophercloud/v2@v2.0.5/openstack/loadbalancer/v2/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 load balancer 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  // UpdateOptsBuilder allows extensions to add additional parameters to the
    17  // Update request.
    18  type UpdateOptsBuilder interface {
    19  	ToQuotaUpdateMap() (map[string]any, error)
    20  }
    21  
    22  // UpdateOpts represents options used to update the load balancer Quotas.
    23  type UpdateOpts struct {
    24  	// Loadbalancer represents the number of load balancers. A "-1" value means no limit.
    25  	Loadbalancer *int `json:"loadbalancer,omitempty"`
    26  
    27  	// Listener represents the number of listeners. A "-1" value means no limit.
    28  	Listener *int `json:"listener,omitempty"`
    29  
    30  	// Member represents the number of members. A "-1" value means no limit.
    31  	Member *int `json:"member,omitempty"`
    32  
    33  	// Poool represents the number of pools. A "-1" value means no limit.
    34  	Pool *int `json:"pool,omitempty"`
    35  
    36  	// HealthMonitor represents the number of healthmonitors. A "-1" value means no limit.
    37  	Healthmonitor *int `json:"healthmonitor,omitempty"`
    38  
    39  	// L7Policy represents the number of l7policies. A "-1" value means no limit.
    40  	L7Policy *int `json:"l7policy,omitempty"`
    41  
    42  	// L7Rule represents the number of l7rules. A "-1" value means no limit.
    43  	L7Rule *int `json:"l7rule,omitempty"`
    44  }
    45  
    46  // ToQuotaUpdateMap builds a request body from UpdateOpts.
    47  func (opts UpdateOpts) ToQuotaUpdateMap() (map[string]any, error) {
    48  	return gophercloud.BuildRequestBody(opts, "quota")
    49  }
    50  
    51  // Update accepts a UpdateOpts struct and updates an existing load balancer Quotas using the
    52  // values provided.
    53  func Update(ctx context.Context, c *gophercloud.ServiceClient, projectID string, opts UpdateOptsBuilder) (r UpdateResult) {
    54  	b, err := opts.ToQuotaUpdateMap()
    55  	if err != nil {
    56  		r.Err = err
    57  		return
    58  	}
    59  	resp, err := c.Put(ctx, updateURL(c, projectID), b, &r.Body, &gophercloud.RequestOpts{
    60  		// allow 200 (neutron/lbaasv2) and 202 (octavia)
    61  		OkCodes: []int{200, 202},
    62  	})
    63  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    64  	return
    65  }