requests.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package stackresources
  2. import (
  3. "devel.mephi.ru/iacherepanov/openstack-gophercloud"
  4. "devel.mephi.ru/iacherepanov/openstack-gophercloud/pagination"
  5. )
  6. // Find retrieves stack resources for the given stack name.
  7. func Find(c *gophercloud.ServiceClient, stackName string) (r FindResult) {
  8. _, r.Err = c.Get(findURL(c, stackName), &r.Body, nil)
  9. return
  10. }
  11. // ListOptsBuilder allows extensions to add additional parameters to the
  12. // List request.
  13. type ListOptsBuilder interface {
  14. ToStackResourceListQuery() (string, error)
  15. }
  16. // ListOpts allows the filtering and sorting of paginated collections through
  17. // the API. Marker and Limit are used for pagination.
  18. type ListOpts struct {
  19. // Include resources from nest stacks up to Depth levels of recursion.
  20. Depth int `q:"nested_depth"`
  21. }
  22. // ToStackResourceListQuery formats a ListOpts into a query string.
  23. func (opts ListOpts) ToStackResourceListQuery() (string, error) {
  24. q, err := gophercloud.BuildQueryString(opts)
  25. return q.String(), err
  26. }
  27. // List makes a request against the API to list resources for the given stack.
  28. func List(client *gophercloud.ServiceClient, stackName, stackID string, opts ListOptsBuilder) pagination.Pager {
  29. url := listURL(client, stackName, stackID)
  30. if opts != nil {
  31. query, err := opts.ToStackResourceListQuery()
  32. if err != nil {
  33. return pagination.Pager{Err: err}
  34. }
  35. url += query
  36. }
  37. return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
  38. return ResourcePage{pagination.SinglePageBase(r)}
  39. })
  40. }
  41. // Get retreives data for the given stack resource.
  42. func Get(c *gophercloud.ServiceClient, stackName, stackID, resourceName string) (r GetResult) {
  43. _, r.Err = c.Get(getURL(c, stackName, stackID, resourceName), &r.Body, nil)
  44. return
  45. }
  46. // Metadata retreives the metadata for the given stack resource.
  47. func Metadata(c *gophercloud.ServiceClient, stackName, stackID, resourceName string) (r MetadataResult) {
  48. _, r.Err = c.Get(metadataURL(c, stackName, stackID, resourceName), &r.Body, nil)
  49. return
  50. }
  51. // ListTypes makes a request against the API to list resource types.
  52. func ListTypes(client *gophercloud.ServiceClient) pagination.Pager {
  53. return pagination.NewPager(client, listTypesURL(client), func(r pagination.PageResult) pagination.Page {
  54. return ResourceTypePage{pagination.SinglePageBase(r)}
  55. })
  56. }
  57. // Schema retreives the schema for the given resource type.
  58. func Schema(c *gophercloud.ServiceClient, resourceType string) (r SchemaResult) {
  59. _, r.Err = c.Get(schemaURL(c, resourceType), &r.Body, nil)
  60. return
  61. }
  62. // Template retreives the template representation for the given resource type.
  63. func Template(c *gophercloud.ServiceClient, resourceType string) (r TemplateResult) {
  64. _, r.Err = c.Get(templateURL(c, resourceType), &r.Body, nil)
  65. return
  66. }