blob: 6ccffc43af8e9b7ecd3316a3fc999a8a5f4d69d3 [file] [log] [blame]
Samuel A. Falvo II17ae5652014-02-12 20:47:43 -08001package images
2
3import (
Ash Wilson7ddf0362014-09-17 10:59:09 -04004 "github.com/racker/perigee"
Ash Wilson9ccf9b62014-09-17 10:07:52 -04005 "github.com/rackspace/gophercloud"
6 "github.com/rackspace/gophercloud/pagination"
Samuel A. Falvo II17ae5652014-02-12 20:47:43 -08007)
8
Jon Perrittef168e62014-10-08 11:14:05 -05009// ListOpts contain options for limiting the number of Images returned from a call to ListDetail.
10type 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.
28func 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 Wilson9ccf9b62014-09-17 10:07:52 -040038 createPage := func(r pagination.LastHTTPResponse) pagination.Page {
Ash Wilson501b4f32014-09-25 15:16:02 -040039 return ImagePage{pagination.LinkedPageBase{LastHTTPResponse: r}}
Samuel A. Falvo II17ae5652014-02-12 20:47:43 -080040 }
41
Jon Perrittef168e62014-10-08 11:14:05 -050042 return pagination.NewPager(client, url, createPage)
Samuel A. Falvo II17ae5652014-02-12 20:47:43 -080043}
Ash Wilson7ddf0362014-09-17 10:59:09 -040044
45// Get acquires additional detail about a specific image by ID.
46// Use ExtractImage() to intepret the result as an openstack Image.
Ash Wilsond2f87032014-09-25 11:34:41 -040047func Get(client *gophercloud.ServiceClient, id string) GetResult {
Ash Wilson7ddf0362014-09-17 10:59:09 -040048 var result GetResult
Jon Perrittef168e62014-10-08 11:14:05 -050049 _, result.Err = perigee.Request("GET", getURL(client, id), perigee.Options{
Ash Wilson7ddf0362014-09-17 10:59:09 -040050 MoreHeaders: client.Provider.AuthenticatedHeaders(),
Ash Wilsond2f87032014-09-25 11:34:41 -040051 Results: &result.Resp,
Ash Wilson7ddf0362014-09-17 10:59:09 -040052 OkCodes: []int{200},
53 })
Ash Wilsond2f87032014-09-25 11:34:41 -040054 return result
Ash Wilson7ddf0362014-09-17 10:59:09 -040055}