Samuel A. Falvo II | 17ae565 | 2014-02-12 20:47:43 -0800 | [diff] [blame] | 1 | package images |
| 2 | |
| 3 | import ( |
Ash Wilson | 7ddf036 | 2014-09-17 10:59:09 -0400 | [diff] [blame] | 4 | "github.com/racker/perigee" |
Ash Wilson | 9ccf9b6 | 2014-09-17 10:07:52 -0400 | [diff] [blame] | 5 | "github.com/rackspace/gophercloud" |
| 6 | "github.com/rackspace/gophercloud/pagination" |
Samuel A. Falvo II | 17ae565 | 2014-02-12 20:47:43 -0800 | [diff] [blame] | 7 | ) |
| 8 | |
Jon Perritt | ef168e6 | 2014-10-08 11:14:05 -0500 | [diff] [blame^] | 9 | // ListOpts contain options for limiting the number of Images returned from a call to ListDetail. |
| 10 | type ListOpts struct { |
| 11 | // When the image last changed status (in date-time format). |
| 12 | ChangesSince string `q:"changes-since"` |
| 13 | // The number of Images to return. |
| 14 | Limit int `q:"limit"` |
| 15 | // UUID of the Image at which to set a marker. |
| 16 | Marker string `q:"marker"` |
| 17 | // The name of the Image. |
| 18 | Name string `q:"name:"` |
| 19 | // The name of the Server (in URL format). |
| 20 | Server string `q:"server"` |
| 21 | // The current status of the Image. |
| 22 | Status string `q:"status"` |
| 23 | // The value of the type of image (e.g. BASE, SERVER, ALL) |
| 24 | Type string `q:"type"` |
| 25 | } |
| 26 | |
| 27 | // ListDetail enumerates the available images. |
| 28 | func ListDetail(client *gophercloud.ServiceClient, opts *ListOpts) pagination.Pager { |
| 29 | url := listDetailURL(client) |
| 30 | if opts != nil { |
| 31 | query, err := gophercloud.BuildQueryString(opts) |
| 32 | if err != nil { |
| 33 | return pagination.Pager{Err: err} |
| 34 | } |
| 35 | url += query.String() |
| 36 | } |
| 37 | |
Ash Wilson | 9ccf9b6 | 2014-09-17 10:07:52 -0400 | [diff] [blame] | 38 | createPage := func(r pagination.LastHTTPResponse) pagination.Page { |
Ash Wilson | 501b4f3 | 2014-09-25 15:16:02 -0400 | [diff] [blame] | 39 | return ImagePage{pagination.LinkedPageBase{LastHTTPResponse: r}} |
Samuel A. Falvo II | 17ae565 | 2014-02-12 20:47:43 -0800 | [diff] [blame] | 40 | } |
| 41 | |
Jon Perritt | ef168e6 | 2014-10-08 11:14:05 -0500 | [diff] [blame^] | 42 | return pagination.NewPager(client, url, createPage) |
Samuel A. Falvo II | 17ae565 | 2014-02-12 20:47:43 -0800 | [diff] [blame] | 43 | } |
Ash Wilson | 7ddf036 | 2014-09-17 10:59:09 -0400 | [diff] [blame] | 44 | |
| 45 | // Get acquires additional detail about a specific image by ID. |
| 46 | // Use ExtractImage() to intepret the result as an openstack Image. |
Ash Wilson | d2f8703 | 2014-09-25 11:34:41 -0400 | [diff] [blame] | 47 | func Get(client *gophercloud.ServiceClient, id string) GetResult { |
Ash Wilson | 7ddf036 | 2014-09-17 10:59:09 -0400 | [diff] [blame] | 48 | var result GetResult |
Jon Perritt | ef168e6 | 2014-10-08 11:14:05 -0500 | [diff] [blame^] | 49 | _, result.Err = perigee.Request("GET", getURL(client, id), perigee.Options{ |
Ash Wilson | 7ddf036 | 2014-09-17 10:59:09 -0400 | [diff] [blame] | 50 | MoreHeaders: client.Provider.AuthenticatedHeaders(), |
Ash Wilson | d2f8703 | 2014-09-25 11:34:41 -0400 | [diff] [blame] | 51 | Results: &result.Resp, |
Ash Wilson | 7ddf036 | 2014-09-17 10:59:09 -0400 | [diff] [blame] | 52 | OkCodes: []int{200}, |
| 53 | }) |
Ash Wilson | d2f8703 | 2014-09-25 11:34:41 -0400 | [diff] [blame] | 54 | return result |
Ash Wilson | 7ddf036 | 2014-09-17 10:59:09 -0400 | [diff] [blame] | 55 | } |