1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
package limits
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// Get retrieves details on a single limit, by ID.
func GetEnforcementModel(client *gophercloud.ServiceClient) (r EnforcementModelResult) {
resp, err := client.Get(enforcementModelURL(client), &r.Body, nil)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
// ListOptsBuilder allows extensions to add additional parameters to
// the List request
type ListOptsBuilder interface {
ToLimitListQuery() (string, error)
}
// ListOpts provides options to filter the List results.
type ListOpts struct {
// Filters the response by a region ID.
RegionID string `q:"region_id"`
// Filters the response by a project ID.
ProjectID string `q:"project_id"`
// Filters the response by a domain ID.
DomainID string `q:"domain_id"`
// Filters the response by a service ID.
ServiceID string `q:"service_id"`
// Filters the response by a resource name.
ResourceName string `q:"resource_name"`
}
// ToLimitListQuery formats a ListOpts into a query string.
func (opts ListOpts) ToLimitListQuery() (string, error) {
q, err := gophercloud.BuildQueryString(opts)
return q.String(), err
}
// List enumerates the limits.
func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
url := rootURL(client)
if opts != nil {
query, err := opts.ToLimitListQuery()
if err != nil {
return pagination.Pager{Err: err}
}
url += query
}
return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
return LimitPage{pagination.LinkedPageBase{PageResult: r}}
})
}
// BatchCreateOptsBuilder allows extensions to add additional parameters to
// the Create request.
type BatchCreateOptsBuilder interface {
ToLimitsCreateMap() (map[string]interface{}, error)
}
type CreateOpts struct {
// RegionID is the ID of the region where the limit is applied.
RegionID string `json:"region_id,omitempty"`
// ProjectID is the ID of the project where the limit is applied.
ProjectID string `json:"project_id,omitempty"`
// DomainID is the ID of the domain where the limit is applied.
DomainID string `json:"domain_id,omitempty"`
// ServiceID is the ID of the service where the limit is applied.
ServiceID string `json:"service_id" required:"true"`
// Description of the limit.
Description string `json:"description,omitempty"`
// ResourceName is the name of the resource that the limit is applied to.
ResourceName string `json:"resource_name" required:"true"`
// ResourceLimit is the override limit.
ResourceLimit int `json:"resource_limit"`
}
// BatchCreateOpts provides options used to create limits.
type BatchCreateOpts []CreateOpts
// ToLimitsCreateMap formats a BatchCreateOpts into a create request.
func (opts BatchCreateOpts) ToLimitsCreateMap() (map[string]interface{}, error) {
limits := make([]map[string]interface{}, len(opts))
for i, limit := range opts {
limitMap, err := limit.ToMap()
if err != nil {
return nil, err
}
limits[i] = limitMap
}
return map[string]interface{}{"limits": limits}, nil
}
func (opts CreateOpts) ToMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "")
}
// BatchCreate creates new Limits.
func BatchCreate(client *gophercloud.ServiceClient, opts BatchCreateOptsBuilder) (r CreateResult) {
b, err := opts.ToLimitsCreateMap()
if err != nil {
r.Err = err
return
}
resp, err := client.Post(rootURL(client), &b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{201},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
// Get retrieves details on a single limit, by ID.
func Get(client *gophercloud.ServiceClient, limitID string) (r GetResult) {
resp, err := client.Get(resourceURL(client, limitID), &r.Body, nil)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
// UpdateOptsBuilder allows extensions to add additional parameters to
// the Update request.
type UpdateOptsBuilder interface {
ToLimitUpdateMap() (map[string]interface{}, error)
}
// UpdateOpts represents parameters to update a domain.
type UpdateOpts struct {
// Description of the limit.
Description *string `json:"description,omitempty"`
// ResourceLimit is the override limit.
ResourceLimit *int `json:"resource_limit,omitempty"`
}
// ToLimitUpdateMap formats UpdateOpts into an update request.
func (opts UpdateOpts) ToLimitUpdateMap() (map[string]interface{}, error) {
return gophercloud.BuildRequestBody(opts, "limit")
}
// Update modifies the attributes of a limit.
func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult) {
b, err := opts.ToLimitUpdateMap()
if err != nil {
r.Err = err
return
}
resp, err := client.Patch(resourceURL(client, id), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
// Delete deletes a limit.
func Delete(client *gophercloud.ServiceClient, limitID string) (r DeleteResult) {
resp, err := client.Delete(resourceURL(client, limitID), nil)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
|