Jon Perritt | 3711cd0 | 2014-12-22 22:20:15 -0700 | [diff] [blame] | 1 | package stackresources |
| 2 | |
| 3 | import ( |
Jon Perritt | 27249f4 | 2016-02-18 10:35:59 -0600 | [diff] [blame] | 4 | "github.com/gophercloud/gophercloud" |
| 5 | "github.com/gophercloud/gophercloud/pagination" |
Jon Perritt | 3711cd0 | 2014-12-22 22:20:15 -0700 | [diff] [blame] | 6 | ) |
| 7 | |
Jon Perritt | 8bdc1a6 | 2015-02-12 09:14:48 -0700 | [diff] [blame] | 8 | // Find retrieves stack resources for the given stack name. |
Jon Perritt | 3860b51 | 2016-03-29 12:01:48 -0500 | [diff] [blame] | 9 | func Find(c *gophercloud.ServiceClient, stackName string) (r FindResult) { |
Jon Perritt | 397ade6 | 2016-03-15 06:55:02 -0500 | [diff] [blame] | 10 | _, r.Err = c.Get(findURL(c, stackName), &r.Body, nil) |
Jon Perritt | 3711cd0 | 2014-12-22 22:20:15 -0700 | [diff] [blame] | 11 | } |
| 12 | |
| 13 | // ListOptsBuilder allows extensions to add additional parameters to the |
| 14 | // List request. |
| 15 | type 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. |
| 21 | type ListOpts struct { |
Jon Perritt | 3711cd0 | 2014-12-22 22:20:15 -0700 | [diff] [blame] | 22 | // 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. |
| 27 | func (opts ListOpts) ToStackResourceListQuery() (string, error) { |
| 28 | q, err := gophercloud.BuildQueryString(opts) |
Jon Perritt | fea9073 | 2016-03-15 02:57:05 -0500 | [diff] [blame] | 29 | return q.String(), err |
Jon Perritt | 3711cd0 | 2014-12-22 22:20:15 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | // List makes a request against the API to list resources for the given stack. |
| 33 | func List(client *gophercloud.ServiceClient, stackName, stackID string, opts ListOptsBuilder) pagination.Pager { |
| 34 | url := listURL(client, stackName, stackID) |
Jon Perritt | 3711cd0 | 2014-12-22 22:20:15 -0700 | [diff] [blame] | 35 | if opts != nil { |
| 36 | query, err := opts.ToStackResourceListQuery() |
| 37 | if err != nil { |
| 38 | return pagination.Pager{Err: err} |
| 39 | } |
| 40 | url += query |
| 41 | } |
Jon Perritt | fea9073 | 2016-03-15 02:57:05 -0500 | [diff] [blame] | 42 | return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { |
Pratik Mallya | 5448f58 | 2015-08-21 12:21:09 -0500 | [diff] [blame] | 43 | return ResourcePage{pagination.SinglePageBase(r)} |
Jon Perritt | fea9073 | 2016-03-15 02:57:05 -0500 | [diff] [blame] | 44 | }) |
Jon Perritt | 3711cd0 | 2014-12-22 22:20:15 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | // Get retreives data for the given stack resource. |
Jon Perritt | 3860b51 | 2016-03-29 12:01:48 -0500 | [diff] [blame] | 48 | func Get(c *gophercloud.ServiceClient, stackName, stackID, resourceName string) (r GetResult) { |
Jon Perritt | fea9073 | 2016-03-15 02:57:05 -0500 | [diff] [blame] | 49 | _, r.Err = c.Get(getURL(c, stackName, stackID, resourceName), &r.Body, nil) |
Jon Perritt | 3711cd0 | 2014-12-22 22:20:15 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | // Metadata retreives the metadata for the given stack resource. |
Jon Perritt | 3860b51 | 2016-03-29 12:01:48 -0500 | [diff] [blame] | 53 | func Metadata(c *gophercloud.ServiceClient, stackName, stackID, resourceName string) (r MetadataResult) { |
Jon Perritt | fea9073 | 2016-03-15 02:57:05 -0500 | [diff] [blame] | 54 | _, r.Err = c.Get(metadataURL(c, stackName, stackID, resourceName), &r.Body, nil) |
Jon Perritt | 3711cd0 | 2014-12-22 22:20:15 -0700 | [diff] [blame] | 55 | } |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 56 | |
| 57 | // ListTypes makes a request against the API to list resource types. |
| 58 | func ListTypes(client *gophercloud.ServiceClient) pagination.Pager { |
Jon Perritt | fea9073 | 2016-03-15 02:57:05 -0500 | [diff] [blame] | 59 | return pagination.NewPager(client, listTypesURL(client), func(r pagination.PageResult) pagination.Page { |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 60 | return ResourceTypePage{pagination.SinglePageBase(r)} |
Jon Perritt | fea9073 | 2016-03-15 02:57:05 -0500 | [diff] [blame] | 61 | }) |
Jon Perritt | a065da1 | 2015-02-06 10:20:16 -0700 | [diff] [blame] | 62 | } |
Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 63 | |
| 64 | // Schema retreives the schema for the given resource type. |
Jon Perritt | 3860b51 | 2016-03-29 12:01:48 -0500 | [diff] [blame] | 65 | func Schema(c *gophercloud.ServiceClient, resourceType string) (r SchemaResult) { |
Jon Perritt | fea9073 | 2016-03-15 02:57:05 -0500 | [diff] [blame] | 66 | _, r.Err = c.Get(schemaURL(c, resourceType), &r.Body, nil) |
Jon Perritt | 1d4aca0 | 2015-02-06 12:29:16 -0700 | [diff] [blame] | 67 | } |
Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 68 | |
| 69 | // Template retreives the template representation for the given resource type. |
Jon Perritt | 3860b51 | 2016-03-29 12:01:48 -0500 | [diff] [blame] | 70 | func Template(c *gophercloud.ServiceClient, resourceType string) (r TemplateResult) { |
Jon Perritt | fea9073 | 2016-03-15 02:57:05 -0500 | [diff] [blame] | 71 | _, r.Err = c.Get(templateURL(c, resourceType), &r.Body, nil) |
Jon Perritt | b1e303a | 2015-02-06 22:15:44 -0700 | [diff] [blame] | 72 | } |