github.com/gophercloud/gophercloud@v1.11.0/openstack/containerinfra/v1/quotas/requests.go (about)

     1  package quotas
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  )
     6  
     7  // CreateOptsBuilder Builder.
     8  type CreateOptsBuilder interface {
     9  	ToQuotaCreateMap() (map[string]interface{}, error)
    10  }
    11  
    12  // CreateOpts params
    13  type CreateOpts struct {
    14  	ProjectID string `json:"project_id"`
    15  	Resource  string `json:"resource"`
    16  	HardLimit int    `json:"hard_limit"`
    17  }
    18  
    19  // ToQuotaCreateMap constructs a request body from CreateOpts.
    20  func (opts CreateOpts) ToQuotaCreateMap() (map[string]interface{}, error) {
    21  	return gophercloud.BuildRequestBody(opts, "")
    22  }
    23  
    24  // Create requests the creation of a new quota.
    25  func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
    26  	b, err := opts.ToQuotaCreateMap()
    27  	if err != nil {
    28  		r.Err = err
    29  		return
    30  	}
    31  	resp, err := client.Post(createURL(client), b, &r.Body, &gophercloud.RequestOpts{
    32  		OkCodes: []int{201},
    33  	})
    34  	_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
    35  	return
    36  }