blob: f33c170e5cad533ed52bcb4803952ce5d7dccb4f [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 Perritt3711cd02014-12-22 22:20:15 -07009func Find(c *gophercloud.ServiceClient, stackName string) FindResult {
Jon Perrittfea90732016-03-15 02:57:05 -050010 var r FindResult
11 _, res.Err = c.Get(findURL(c, stackName), &res.Body, nil)
12 return r
Jon Perritt3711cd02014-12-22 22:20:15 -070013}
14
15// ListOptsBuilder allows extensions to add additional parameters to the
16// List request.
17type ListOptsBuilder interface {
18 ToStackResourceListQuery() (string, error)
19}
20
21// ListOpts allows the filtering and sorting of paginated collections through
22// the API. Marker and Limit are used for pagination.
23type ListOpts struct {
Jon Perritt3711cd02014-12-22 22:20:15 -070024 // Include resources from nest stacks up to Depth levels of recursion.
25 Depth int `q:"nested_depth"`
26}
27
28// ToStackResourceListQuery formats a ListOpts into a query string.
29func (opts ListOpts) ToStackResourceListQuery() (string, error) {
30 q, err := gophercloud.BuildQueryString(opts)
Jon Perrittfea90732016-03-15 02:57:05 -050031 return q.String(), err
Jon Perritt3711cd02014-12-22 22:20:15 -070032}
33
34// List makes a request against the API to list resources for the given stack.
35func List(client *gophercloud.ServiceClient, stackName, stackID string, opts ListOptsBuilder) pagination.Pager {
36 url := listURL(client, stackName, stackID)
Jon Perritt3711cd02014-12-22 22:20:15 -070037 if opts != nil {
38 query, err := opts.ToStackResourceListQuery()
39 if err != nil {
40 return pagination.Pager{Err: err}
41 }
42 url += query
43 }
Jon Perrittfea90732016-03-15 02:57:05 -050044 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
Pratik Mallya5448f582015-08-21 12:21:09 -050045 return ResourcePage{pagination.SinglePageBase(r)}
Jon Perrittfea90732016-03-15 02:57:05 -050046 })
Jon Perritt3711cd02014-12-22 22:20:15 -070047}
48
49// Get retreives data for the given stack resource.
50func Get(c *gophercloud.ServiceClient, stackName, stackID, resourceName string) GetResult {
Jon Perrittfea90732016-03-15 02:57:05 -050051 var r GetResult
52 _, r.Err = c.Get(getURL(c, stackName, stackID, resourceName), &r.Body, nil)
53 return r
Jon Perritt3711cd02014-12-22 22:20:15 -070054}
55
56// Metadata retreives the metadata for the given stack resource.
57func Metadata(c *gophercloud.ServiceClient, stackName, stackID, resourceName string) MetadataResult {
Jon Perrittfea90732016-03-15 02:57:05 -050058 var r MetadataResult
59 _, r.Err = c.Get(metadataURL(c, stackName, stackID, resourceName), &r.Body, nil)
60 return r
Jon Perritt3711cd02014-12-22 22:20:15 -070061}
Jon Perritta065da12015-02-06 10:20:16 -070062
63// ListTypes makes a request against the API to list resource types.
64func ListTypes(client *gophercloud.ServiceClient) pagination.Pager {
Jon Perrittfea90732016-03-15 02:57:05 -050065 return pagination.NewPager(client, listTypesURL(client), func(r pagination.PageResult) pagination.Page {
Jon Perritta065da12015-02-06 10:20:16 -070066 return ResourceTypePage{pagination.SinglePageBase(r)}
Jon Perrittfea90732016-03-15 02:57:05 -050067 })
Jon Perritta065da12015-02-06 10:20:16 -070068}
Jon Perritt1d4aca02015-02-06 12:29:16 -070069
70// Schema retreives the schema for the given resource type.
71func Schema(c *gophercloud.ServiceClient, resourceType string) SchemaResult {
Jon Perrittfea90732016-03-15 02:57:05 -050072 var r SchemaResult
73 _, r.Err = c.Get(schemaURL(c, resourceType), &r.Body, nil)
74 return r
Jon Perritt1d4aca02015-02-06 12:29:16 -070075}
Jon Perrittb1e303a2015-02-06 22:15:44 -070076
77// Template retreives the template representation for the given resource type.
78func Template(c *gophercloud.ServiceClient, resourceType string) TemplateResult {
Jon Perrittfea90732016-03-15 02:57:05 -050079 var r TemplateResult
80 _, r.Err = c.Get(templateURL(c, resourceType), &r.Body, nil)
81 return r
Jon Perrittb1e303a2015-02-06 22:15:44 -070082}