Joe Topjian | 71b85bd | 2017-03-09 18:55:36 -0700 | [diff] [blame] | 1 | package zones |
| 2 | |
| 3 | import ( |
Krzysztof Szukiełojć | 3f41d08 | 2017-05-07 14:43:06 +0200 | [diff] [blame] | 4 | "gerrit.mcp.mirantis.net/debian/gophercloud.git" |
Krzysztof Szukiełojć | 24a29ce | 2017-05-07 14:24:02 +0200 | [diff] [blame] | 5 | "gerrit.mcp.mirantis.net/debian/gophercloud.git/pagination" |
Joe Topjian | 71b85bd | 2017-03-09 18:55:36 -0700 | [diff] [blame] | 6 | ) |
| 7 | |
| 8 | type ListOptsBuilder interface { |
| 9 | ToZoneListQuery() (string, error) |
| 10 | } |
| 11 | |
| 12 | // ListOpts allows the filtering and sorting of paginated collections through |
| 13 | // the API. Filtering is achieved by passing in struct field values that map to |
| 14 | // the server attributes you want to see returned. Marker and Limit are used |
| 15 | // for pagination. |
| 16 | // https://developer.openstack.org/api-ref/dns/ |
| 17 | type ListOpts struct { |
| 18 | // Integer value for the limit of values to return. |
| 19 | Limit int `q:"limit"` |
| 20 | |
| 21 | // UUID of the zone at which you want to set a marker. |
| 22 | Marker string `q:"marker"` |
| 23 | |
| 24 | Description string `q:"description"` |
| 25 | Email string `q:"email"` |
| 26 | Name string `q:"name"` |
| 27 | SortDir string `q:"sort_dir"` |
| 28 | SortKey string `q:"sort_key"` |
| 29 | Status string `q:"status"` |
| 30 | TTL int `q:"ttl"` |
| 31 | Type string `q:"type"` |
| 32 | } |
| 33 | |
| 34 | func (opts ListOpts) ToZoneListQuery() (string, error) { |
| 35 | q, err := gophercloud.BuildQueryString(opts) |
| 36 | return q.String(), err |
| 37 | } |
| 38 | |
| 39 | func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager { |
| 40 | url := listURL(client) |
| 41 | if opts != nil { |
| 42 | query, err := opts.ToZoneListQuery() |
| 43 | if err != nil { |
| 44 | return pagination.Pager{Err: err} |
| 45 | } |
| 46 | url += query |
| 47 | } |
| 48 | return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page { |
| 49 | return ZonePage{pagination.LinkedPageBase{PageResult: r}} |
| 50 | }) |
| 51 | } |
| 52 | |
| 53 | // Get returns additional information about a zone, given its ID. |
| 54 | func Get(client *gophercloud.ServiceClient, zoneID string) (r GetResult) { |
| 55 | _, r.Err = client.Get(zoneURL(client, zoneID), &r.Body, nil) |
| 56 | return |
| 57 | } |