Krzysztof Szukiełojć | 7cf0b33 | 2017-05-18 08:46:42 +0200 | [diff] [blame^] | 1 | package snapshots |
| 2 | |
| 3 | import ( |
| 4 | gophercloud "gerrit.mcp.mirantis.net/debian/gophercloud.git" |
| 5 | "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination" |
| 6 | ) |
| 7 | |
| 8 | // ListOptsBuilder allows extensions to add additional parameters to the List |
| 9 | // request. |
| 10 | type ListOptsBuilder interface { |
| 11 | ToVolumeListQuery() (string, error) |
| 12 | } |
| 13 | |
| 14 | type ListOpts struct { |
| 15 | // admin-only option. Set it to true to see all tenant volumes. |
| 16 | AllTenants bool `q:"all_tenants"` |
| 17 | } |
| 18 | |
| 19 | // ToVolumeListQuery formats a ListOpts into a query string. |
| 20 | func (opts ListOpts) ToVolumeListQuery() (string, error) { |
| 21 | q, err := gophercloud.BuildQueryString(opts) |
| 22 | return q.String(), err |
| 23 | } |
| 24 | |
| 25 | // List returns Volumes optionally limited by the conditions provided in ListOpts. |
| 26 | func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { |
| 27 | url := listURL(client) |
| 28 | if opts != nil { |
| 29 | query, err := opts.ToVolumeListQuery() |
| 30 | if err != nil { |
| 31 | return pagination.Pager{Err: err} |
| 32 | } |
| 33 | url += query |
| 34 | } |
| 35 | |
| 36 | return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { |
| 37 | return SnapshotPage{pagination.SinglePageBase(r)} |
| 38 | }) |
| 39 | } |