blob: 2461200ff00363c9032282ead4ddf5c93bd36502 [file] [log] [blame]
package stackresources
import (
"github.com/racker/perigee"
"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/pagination"
)
// Find retreives stack resources for the given stack name.
func Find(c *gophercloud.ServiceClient, stackName string) FindResult {
var res FindResult
// Send request to API
_, res.Err = perigee.Request("GET", findURL(c, stackName), perigee.Options{
MoreHeaders: c.AuthenticatedHeaders(),
Results: &res.Body,
OkCodes: []int{302},
})
return res
}
// ListOptsBuilder allows extensions to add additional parameters to the
// List request.
type ListOptsBuilder interface {
ToStackResourceListQuery() (string, error)
}
// ListOpts allows the filtering and sorting of paginated collections through
// the API. Marker and Limit are used for pagination.
type ListOpts struct {
// The stack resource ID with which to start the listing.
Marker string `q:"marker"`
// Integer value for the limit of values to return.
Limit int `q:"limit"`
// Include resources from nest stacks up to Depth levels of recursion.
Depth int `q:"nested_depth"`
}
// ToStackResourceListQuery formats a ListOpts into a query string.
func (opts ListOpts) ToStackResourceListQuery() (string, error) {
q, err := gophercloud.BuildQueryString(opts)
if err != nil {
return "", err
}
return q.String(), nil
}
// List makes a request against the API to list resources for the given stack.
func List(client *gophercloud.ServiceClient, stackName, stackID string, opts ListOptsBuilder) pagination.Pager {
url := listURL(client, stackName, stackID)
if opts != nil {
query, err := opts.ToStackResourceListQuery()
if err != nil {
return pagination.Pager{Err: err}
}
url += query
}
createPageFn := func(r pagination.PageResult) pagination.Page {
return ResourcePage{pagination.LinkedPageBase{PageResult: r}}
}
return pagination.NewPager(client, url, createPageFn)
}
// Get retreives data for the given stack resource.
func Get(c *gophercloud.ServiceClient, stackName, stackID, resourceName string) GetResult {
var res GetResult
// Send request to API
_, res.Err = perigee.Request("GET", getURL(c, stackName, stackID, resourceName), perigee.Options{
MoreHeaders: c.AuthenticatedHeaders(),
Results: &res.Body,
OkCodes: []int{200},
})
return res
}
// Metadata retreives the metadata for the given stack resource.
func Metadata(c *gophercloud.ServiceClient, stackName, stackID, resourceName string) MetadataResult {
var res MetadataResult
// Send request to API
_, res.Err = perigee.Request("GET", metadataURL(c, stackName, stackID, resourceName), perigee.Options{
MoreHeaders: c.AuthenticatedHeaders(),
Results: &res.Body,
OkCodes: []int{200},
})
return res
}