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