blob: cc4b990c7853317bf268c695925f305c6464de25 [file] [log] [blame]
Jon Perritt3711cd02014-12-22 22:20:15 -07001package stackresources
2
3import (
Jon Perritt27249f42016-02-18 10:35:59 -06004 "github.com/gophercloud/gophercloud"
5 "github.com/gophercloud/gophercloud/pagination"
Jon Perritt3711cd02014-12-22 22:20:15 -07006)
7
Jon Perritt8bdc1a62015-02-12 09:14:48 -07008// Find retrieves stack resources for the given stack name.
Jon Perritt3860b512016-03-29 12:01:48 -05009func Find(c *gophercloud.ServiceClient, stackName string) (r FindResult) {
Jon Perritt397ade62016-03-15 06:55:02 -050010 _, r.Err = c.Get(findURL(c, stackName), &r.Body, nil)
Jon Perritt3711cd02014-12-22 22:20:15 -070011}
12
13// ListOptsBuilder allows extensions to add additional parameters to the
14// List request.
15type ListOptsBuilder interface {
16 ToStackResourceListQuery() (string, error)
17}
18
19// ListOpts allows the filtering and sorting of paginated collections through
20// the API. Marker and Limit are used for pagination.
21type ListOpts struct {
Jon Perritt3711cd02014-12-22 22:20:15 -070022 // Include resources from nest stacks up to Depth levels of recursion.
23 Depth int `q:"nested_depth"`
24}
25
26// ToStackResourceListQuery formats a ListOpts into a query string.
27func (opts ListOpts) ToStackResourceListQuery() (string, error) {
28 q, err := gophercloud.BuildQueryString(opts)
Jon Perrittfea90732016-03-15 02:57:05 -050029 return q.String(), err
Jon Perritt3711cd02014-12-22 22:20:15 -070030}
31
32// List makes a request against the API to list resources for the given stack.
33func List(client *gophercloud.ServiceClient, stackName, stackID string, opts ListOptsBuilder) pagination.Pager {
34 url := listURL(client, stackName, stackID)
Jon Perritt3711cd02014-12-22 22:20:15 -070035 if opts != nil {
36 query, err := opts.ToStackResourceListQuery()
37 if err != nil {
38 return pagination.Pager{Err: err}
39 }
40 url += query
41 }
Jon Perrittfea90732016-03-15 02:57:05 -050042 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
Pratik Mallya5448f582015-08-21 12:21:09 -050043 return ResourcePage{pagination.SinglePageBase(r)}
Jon Perrittfea90732016-03-15 02:57:05 -050044 })
Jon Perritt3711cd02014-12-22 22:20:15 -070045}
46
47// Get retreives data for the given stack resource.
Jon Perritt3860b512016-03-29 12:01:48 -050048func Get(c *gophercloud.ServiceClient, stackName, stackID, resourceName string) (r GetResult) {
Jon Perrittfea90732016-03-15 02:57:05 -050049 _, r.Err = c.Get(getURL(c, stackName, stackID, resourceName), &r.Body, nil)
Jon Perritt3711cd02014-12-22 22:20:15 -070050}
51
52// Metadata retreives the metadata for the given stack resource.
Jon Perritt3860b512016-03-29 12:01:48 -050053func Metadata(c *gophercloud.ServiceClient, stackName, stackID, resourceName string) (r MetadataResult) {
Jon Perrittfea90732016-03-15 02:57:05 -050054 _, r.Err = c.Get(metadataURL(c, stackName, stackID, resourceName), &r.Body, nil)
Jon Perritt3711cd02014-12-22 22:20:15 -070055}
Jon Perritta065da12015-02-06 10:20:16 -070056
57// ListTypes makes a request against the API to list resource types.
58func ListTypes(client *gophercloud.ServiceClient) pagination.Pager {
Jon Perrittfea90732016-03-15 02:57:05 -050059 return pagination.NewPager(client, listTypesURL(client), func(r pagination.PageResult) pagination.Page {
Jon Perritta065da12015-02-06 10:20:16 -070060 return ResourceTypePage{pagination.SinglePageBase(r)}
Jon Perrittfea90732016-03-15 02:57:05 -050061 })
Jon Perritta065da12015-02-06 10:20:16 -070062}
Jon Perritt1d4aca02015-02-06 12:29:16 -070063
64// Schema retreives the schema for the given resource type.
Jon Perritt3860b512016-03-29 12:01:48 -050065func Schema(c *gophercloud.ServiceClient, resourceType string) (r SchemaResult) {
Jon Perrittfea90732016-03-15 02:57:05 -050066 _, r.Err = c.Get(schemaURL(c, resourceType), &r.Body, nil)
Jon Perritt1d4aca02015-02-06 12:29:16 -070067}
Jon Perrittb1e303a2015-02-06 22:15:44 -070068
69// Template retreives the template representation for the given resource type.
Jon Perritt3860b512016-03-29 12:01:48 -050070func Template(c *gophercloud.ServiceClient, resourceType string) (r TemplateResult) {
Jon Perrittfea90732016-03-15 02:57:05 -050071 _, r.Err = c.Get(templateURL(c, resourceType), &r.Body, nil)
Jon Perrittb1e303a2015-02-06 22:15:44 -070072}