github.com/gophercloud/gophercloud@v1.11.0/openstack/networking/v2/extensions/quotas/requests.go (about)

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