blob: f368b76c6dee4115070e73c83925a0aeed4b946b [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)
jrperritt29ae6b32016-04-13 12:59:37 -050011 return
Jon Perritt3711cd02014-12-22 22:20:15 -070012}
13
14// ListOptsBuilder allows extensions to add additional parameters to the
15// List request.
16type ListOptsBuilder interface {
17 ToStackResourceListQuery() (string, error)
18}
19
20// ListOpts allows the filtering and sorting of paginated collections through
21// the API. Marker and Limit are used for pagination.
22type ListOpts struct {
Jon Perritt3711cd02014-12-22 22:20:15 -070023 // Include resources from nest stacks up to Depth levels of recursion.
24 Depth int `q:"nested_depth"`
25}
26
27// ToStackResourceListQuery formats a ListOpts into a query string.
28func (opts ListOpts) ToStackResourceListQuery() (string, error) {
29 q, err := gophercloud.BuildQueryString(opts)
Jon Perrittfea90732016-03-15 02:57:05 -050030 return q.String(), err
Jon Perritt3711cd02014-12-22 22:20:15 -070031}
32
33// List makes a request against the API to list resources for the given stack.
34func List(client *gophercloud.ServiceClient, stackName, stackID string, opts ListOptsBuilder) pagination.Pager {
35 url := listURL(client, stackName, stackID)
Jon Perritt3711cd02014-12-22 22:20:15 -070036 if opts != nil {
37 query, err := opts.ToStackResourceListQuery()
38 if err != nil {
39 return pagination.Pager{Err: err}
40 }
41 url += query
42 }
Jon Perrittfea90732016-03-15 02:57:05 -050043 return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
Pratik Mallya5448f582015-08-21 12:21:09 -050044 return ResourcePage{pagination.SinglePageBase(r)}
Jon Perrittfea90732016-03-15 02:57:05 -050045 })
Jon Perritt3711cd02014-12-22 22:20:15 -070046}
47
48// Get retreives data for the given stack resource.
Jon Perritt3860b512016-03-29 12:01:48 -050049func Get(c *gophercloud.ServiceClient, stackName, stackID, resourceName string) (r GetResult) {
Jon Perrittfea90732016-03-15 02:57:05 -050050 _, r.Err = c.Get(getURL(c, stackName, stackID, resourceName), &r.Body, nil)
jrperritt29ae6b32016-04-13 12:59:37 -050051 return
Jon Perritt3711cd02014-12-22 22:20:15 -070052}
53
54// Metadata retreives the metadata for the given stack resource.
Jon Perritt3860b512016-03-29 12:01:48 -050055func Metadata(c *gophercloud.ServiceClient, stackName, stackID, resourceName string) (r MetadataResult) {
Jon Perrittfea90732016-03-15 02:57:05 -050056 _, r.Err = c.Get(metadataURL(c, stackName, stackID, resourceName), &r.Body, nil)
jrperritt29ae6b32016-04-13 12:59:37 -050057 return
Jon Perritt3711cd02014-12-22 22:20:15 -070058}
Jon Perritta065da12015-02-06 10:20:16 -070059
60// ListTypes makes a request against the API to list resource types.
61func ListTypes(client *gophercloud.ServiceClient) pagination.Pager {
Jon Perrittfea90732016-03-15 02:57:05 -050062 return pagination.NewPager(client, listTypesURL(client), func(r pagination.PageResult) pagination.Page {
Jon Perritta065da12015-02-06 10:20:16 -070063 return ResourceTypePage{pagination.SinglePageBase(r)}
Jon Perrittfea90732016-03-15 02:57:05 -050064 })
Jon Perritta065da12015-02-06 10:20:16 -070065}
Jon Perritt1d4aca02015-02-06 12:29:16 -070066
67// Schema retreives the schema for the given resource type.
Jon Perritt3860b512016-03-29 12:01:48 -050068func Schema(c *gophercloud.ServiceClient, resourceType string) (r SchemaResult) {
Jon Perrittfea90732016-03-15 02:57:05 -050069 _, r.Err = c.Get(schemaURL(c, resourceType), &r.Body, nil)
jrperritt29ae6b32016-04-13 12:59:37 -050070 return
Jon Perritt1d4aca02015-02-06 12:29:16 -070071}
Jon Perrittb1e303a2015-02-06 22:15:44 -070072
73// Template retreives the template representation for the given resource type.
Jon Perritt3860b512016-03-29 12:01:48 -050074func Template(c *gophercloud.ServiceClient, resourceType string) (r TemplateResult) {
Jon Perrittfea90732016-03-15 02:57:05 -050075 _, r.Err = c.Get(templateURL(c, resourceType), &r.Body, nil)
jrperritt29ae6b32016-04-13 12:59:37 -050076 return
Jon Perrittb1e303a2015-02-06 22:15:44 -070077}