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
|
package resourceproviders
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/pagination"
)
// ListOptsBuilder allows extensions to add additional parameters to the
// List request.
type ListOptsBuilder interface {
ToResourceProviderListQuery() (string, error)
}
// ListOpts allows the filtering resource providers. Filtering is achieved by
// passing in struct field values that map to the resource provider attributes
// you want to see returned.
type ListOpts struct {
// Name is the name of the resource provider to filter the list
Name string `q:"name"`
// UUID is the uuid of the resource provider to filter the list
UUID string `q:"uuid"`
// MemberOf is a string representing aggregate uuids to filter or exclude from the list
MemberOf string `q:"member_of"`
// Resources is a comma-separated list of string indicating an amount of resource
// of a specified class that a provider must have the capacity and availability to serve
Resources string `q:"resources"`
// InTree is a string that represents a resource provider UUID. The returned resource
// providers will be in the same provider tree as the specified provider.
InTree string `q:"in_tree"`
// Required is comma-delimited list of string trait names.
Required string `q:"required"`
}
// ToResourceProviderListQuery formats a ListOpts into a query string.
func (opts ListOpts) ToResourceProviderListQuery() (string, error) {
q, err := gophercloud.BuildQueryString(opts)
return q.String(), err
}
// List makes a request against the API to list resource providers.
func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
url := resourceProvidersListURL(client)
if opts != nil {
query, err := opts.ToResourceProviderListQuery()
if err != nil {
return pagination.Pager{Err: err}
}
url += query
}
return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
return ResourceProvidersPage{pagination.SinglePageBase(r)}
})
}
// CreateOptsBuilder allows extensions to add additional parameters to the
// Create request.
type CreateOptsBuilder interface {
ToResourceProviderCreateMap() (map[string]interface{}, error)
}
// CreateOpts represents options used to create a resource provider.
type CreateOpts struct {
Name string `json:"name"`
UUID string `json:"uuid,omitempty"`
}
// ToResourceProviderCreateMap constructs a request body from CreateOpts.
func (opts CreateOpts) ToResourceProviderCreateMap() (map[string]interface{}, error) {
b, err := gophercloud.BuildRequestBody(opts, "")
if err != nil {
return nil, err
}
return b, nil
}
// Create makes a request against the API to create a resource provider
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult) {
b, err := opts.ToResourceProviderCreateMap()
if err != nil {
r.Err = err
return
}
resp, err := client.Post(resourceProvidersListURL(client), b, &r.Body, &gophercloud.RequestOpts{
OkCodes: []int{200},
})
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
func GetUsages(client *gophercloud.ServiceClient, resourceProviderID string) (r GetUsagesResult) {
resp, err := client.Get(getResourceProviderUsagesURL(client, resourceProviderID), &r.Body, nil)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
func GetInventories(client *gophercloud.ServiceClient, resourceProviderID string) (r GetInventoriesResult) {
resp, err := client.Get(getResourceProviderInventoriesURL(client, resourceProviderID), &r.Body, nil)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
func GetTraits(client *gophercloud.ServiceClient, resourceProviderID string) (r GetTraitsResult) {
resp, err := client.Get(getResourceProviderTraitsURL(client, resourceProviderID), &r.Body, nil)
_, r.Header, r.Err = gophercloud.ParseResponse(resp, err)
return
}
|